TestController.php 27.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
<?php
namespace console\controllers;
/**
 * Created by PhpStorm.
 * User: scott
 * Date: 8/15/18
 * Time: 11:32 AM
 */



use app\wx\modules\user\helpers\UserOrderHelper;
use common\business\AdminCloseOrder;
use common\business\CancelOrder;
use common\business\Deduction;

use common\exts\Invoice\baiwang\InvoiceApi;
use common\exts\privatenumber\PrivateNumber;
use common\exts\wechat\Http;

use common\helpers\DeviceSearch;
use common\helpers\Distance;
use common\helpers\FileManager;

use common\helpers\ImageManager;
use common\helpers\MinaHelper;
use common\helpers\OrderSqlHelper;
use common\helpers\UserMPHelper;
use common\helpers\WxHelper;
use common\models\BindDeviceApply;
use common\models\Engineer;
use common\models\EngineerEvent;
use common\models\EngineerPickOrder;
use common\models\Invoice;
use common\models\PrivateNumberBindRecord;
use common\models\PrivateNumberVoice;
use common\models\RepairOrder;

use common\models\RepairOrderDeduction;


use common\services\wxs\SmsMessage;
use console\models\ClearFileTask;
use console\models\EngineerTask;

use domain\data\EngineerReport;
use domain\device\BindQrcodeApplyRepository;
use domain\engineer\EngineerAchievementPro;
use domain\engineer\EngineerRepository;
use domain\finance\EngineerCashFlow;
use domain\finance\EngineerCashFlowStatus;
use domain\finance\EngineerCashFlowType;
use domain\marketing\activity\DeductionActivityRepository;

use domain\marketing\subsidy\ApplyAwardRule;
use domain\marketing\thankfee\ThankFee;
use domain\system\message\CustomMessage;
use domain\trade\dob\DispatchOrder;

use domain\trade\OnsiteOrder;
use domain\trade\privateorder\PrivateOrderUserOp;
use domain\trade\RepairOrderRepository;
use GuzzleHttp\Psr7;
use Workerman\Worker;
use yii\console\Controller;
use yii\db\Query;
use yii\base\Exception;

use function chr;
use yii\helpers\ArrayHelper;

class TestController extends Controller
{

    public function actionCallT()
    {
        //设备报修:22.552092, 113.927124, 工程师 ,
        //echo Distance::getDistance(22.561575,113.891098, 22.554621,113.906006);
        echo "start";
        echo (null !== '0');
        echo "end";

        //
        $mailList = array('xukexuzhun1@163.com', 'perelmen@qq.com');

        /*
        foreach ($mailList as $mail) {
            $emailSendHandle = \yii::$app->invoice_mailer->compose();
            $emailSendHandle->setTo($mail);
            $emailSendHandle->setTextBody('深圳下大雨了 delete');
            $emailSendHandle->setSubject('深圳下大雨了 subject ....');
            $result = $emailSendHandle->send();

            echo $result ."\r\n";
        }
        */
        //$str = "2018-09-04 09:00:00";
        //$result = DeviceSearch::splitText('[沧田中]税]x金典');
        //print_r($result);
        //echo round('33.1',0);

        //echo Deduction::coverInt(0.9);

        //$returnArr = Deduction::randomUserTag(9, 4);
        //shuffle($returnArr);
        //print_r($returnArr);
        //echo sprintf('%d', 2.00);

    }




    public function actionBindPhone()
    {
        $numbers = PrivateNumber::getAllPrivateNumbers();
        $result = PrivateNumber::bindNumber( '17724017057','17004894899');
        //echo PrivateNumber::$postResponseStr;
        echo "\r\n";
        echo $result;
    }

    public function actionBatchBindPhone()
    {
        $query = new Query();
        $query->from("jwx_engineer");
        $query->select("id, mobile");
        $query->offset(0);
        $query->orderBy("id asc");
        $query->limit(810);
        $engineers = $query->all();

        $engineerLen = count($engineers);
        $pair = (int)$engineerLen /2;

        $st = time();
        echo 'start:'.$st;
        echo "\r\n";
        $redis = \yii::$app->redis;
        $count = 0;
        for($i = 0; $i < $pair; $i++) {
            $j = $pair + $i;
            $rKey = 'mobile_'.$engineers[$i]['mobile']."__". $engineers[$j]['mobile'];
            //$redis->del($rKey);
            $result = PrivateNumber::bindNumber($engineers[$i]['mobile'], $engineers[$j]['mobile']);
            //$redis->set($rKey,$result);
            $resultJson = json_decode($result);
            if ( '000000' == $resultJson->code) {
                $count++;
            }
            echo $rKey;
            echo $result ."\r\n";

        }
        echo "pair:".$pair;
        echo "\r\n";
        $et = time();
        echo 'end:'.$et;
        echo "\r\n";
        echo "t:".($et - $st);
        echo "\r\n";
        echo "ok:".$count;
        echo "\r\n";
    }
    public function actionBatchUnbindPhone()
    {
        $ids = [269,301,314,316,320,322,330,339,344,345,350,369,378,380];
        $privateNumberRecordModel = PrivateNumberBindRecord::find();
        $privateNumberRecordModel->where(['id' => $ids]);
        $privateNumberRecordModel->asArray();
        $records = $privateNumberRecordModel->all();
        $tt = time();
        foreach($records as $record){
            $recordModel = PrivateNumberBindRecord::findOne($record['id']);
            if($recordModel) {
                //$result = PrivateNumber::unbindNumber($record['subscription_id'], 2);
                //echo $result. "\r\n";
                //$recordModel->status = 0;
                //$recordModel->is_main = 2;
                $recordModel->unbind_at = $tt;
                $recordModel->unbind_desc = '超时手动解绑';
                $result2 = $recordModel->save();
                echo "result:". $result2. '__';

                echo $recordModel->subscription_id. "\r\n";

            }
        }
    }
    public function actionAna()
    {
        $redis = \yii::$app->redis;
        $records = $redis->hgetall('mobile*');
        print_r($records);
    }

    public function actionUnbindPhone()
    {
        $subscriptionId = '17150372466'; //8617150372466  17150372300
        $result = PrivateNumber::unbindNumber($subscriptionId, 1);
        //echo PrivateNumber::$postResponseStr;
        echo "\r\n";
        echo $result;

    }

    public function actionQueryPhone()
    {
        $numbers = PrivateNumber::getAllPrivateNumbers();
        $result = PrivateNumber::queryOrderedNumber('17150372300');
        echo $result;
    }

    public function actionQueryVoiceRecord()
    {
        $subscribeId = '66053756068216559371537933854093';
        $st = PrivateNumber::coverTimeStampToPHP('2018-09-26T03:46:07Z');
        $ed = PrivateNumber::coverTimeStampToPHP('2018-09-26T06:49:01Z');
        $result = PrivateNumber::queryVoiceRecord('fa2b53fb-2a95-49e5-9a5d-9f2b403a8295', '2018-09-26 14:30:00','2018-09-26 14:50:00');
        echo $result;
    }

    public function actionGetVoice()
    {
        $arr = ['66261453769654176011542769693114'];
    $privateModel = PrivateNumberVoice::find();
        $privateModel->where(['call_identifier' => $arr]);
        $privateModel->asArray();
        $voiceArr = $privateModel->all();
        foreach($voiceArr as $k=>$v){
            $call_id = $v['call_identifier'];
            echo $v['path']."\r\n";
            $result = PrivateNumber::getRecordDownloadURL($call_id);

            $path = \yii::getAlias('@app/runtime') . "/empty/".$call_id.".wav";

            $local_file = fopen($path, 'w');
            if (false !== $local_file){
                if (false !== fwrite($local_file, $result)) {
                    fclose($local_file);
                    $savePath = $v['path'];
                    FileManager::add($path , $savePath);
                }
            }
        }
    }

    public function actionAddOssFile()
    {
        $file = '/s201812211218389859.pdf';
        $path = \yii::getAlias('@app/runtime') .  $file ;
        $ossSavePath = 'invoice/20181221/s201812211218389859.pdf';
        FileManager::add($path , $ossSavePath);
        echo "end";
    }

    public function actionTestCall()
    {
        //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::bindNumber('15622137119', '15999944931');
        //{"Message":"OK","RequestId":"1EE31873-4053-44F5-B2B4-031ECC4671F7","Code":"OK","SecretBindDTO":{"Extension":"15999944931","SecretNo":"13143439849","SubsId":"974715743568877041"}
        //echo json_encode($result);
        echo "\r\n";

        //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::unbindSubscription('974715743568877041', '13143439849');
        //echo json_encode($result);

        //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::querySubscriptionDetail('134915943835832737', '17097534251');
        //echo json_encode($result, JSON_UNESCAPED_UNICODE);echo "\r\n";


        //$result = \common\exts\Aliyun\DYPLS\PrivateNumber::queryRecordFileDownloadUrl("415c0511041a2151", date('Y-m-d H:i:s', 1543835908));
        //echo json_encode($result, JSON_UNESCAPED_UNICODE);echo "\r\n";
        //{"Message":"OK","RequestId":"7CFD87F7-1FA9-4EFE-BBCA-CCF4CB6F1FD4","DownloadUrl":"http:\/\/secret-axb-record-files.oss-cn-shanghai.aliyuncs.com\/134915943835832737_415c0511041a2151.mp3?Expires=1543843500&OSSAccessKeyId=LTAI27GqAW1VrcQA&Signature=eEATuKSQDIxUurnSuqghV09D3yE%3D","Code":"OK"}
    }

    public function actionDeduction()
    {
        $repairOrderModel = RepairOrder::findOne(['uuid' => '4ba0976b7a0d3d16ae1de634a6201134']);
        $activityModel = DeductionActivityRepository::getCurrentActivity();
        $repairOrderDeduction = RepairOrderDeduction::findOne([
            'repair_order_id'   => $repairOrderModel->id,
            'activity_id'       => $activityModel->id,
        ]);

        $expireTime = $activityModel->expired_time;
        $re = Deduction::canDeduction($repairOrderDeduction, $repairOrderModel, $expireTime);
        Deduction::setRiseVale($repairOrderModel, $expireTime);
        if (0 == $re->errCode) {
            echo $re->error."--1\r\n";
            return ;
        }
        $saveData = ['userTagId' => rand(1,4)];
        $clientUserId = 8;
        $addResult = Deduction::addDeductionAmount($activityModel, $repairOrderModel, $clientUserId, $saveData);
        echo $addResult->error."\r\n";
    }

    /**
     * 初始化5元抵扣券
     */
    public function actionAddDe()
    {
        $repairOrderModel = RepairOrder::findOne(['uuid' => '4ba0976b7a0d3d16ae1de634a6201134']);
        $activityModel = DeductionActivityRepository::getCurrentActivity();

        $result = Deduction::initOrderDeduction($repairOrderModel, $activityModel->uuid);
        if (1 == $result->errCode) {
            echo "add ok\r\n";
        } else {
            echo $result->error."\r\n";
        }
        Deduction::getActivityInfoByOrderUUId('4ba0976b7a0d3d16ae1de634a6201134s');
    }

    public function actionGetFriends()
    {
        $result = Deduction::getRecords('9a4ba1dcae263f11893e707d733e3593', 4, 0);
        print_r($result);
    }

    public function actionDeductionPage()
    {
        $orderUUId = '';//$this->request->post('id');
        $e = new \stdClass();
        $e->success = true;
        $e->canClick = true;
        $e->selectedTagId = '';
        $e->clickResult = 0;
        $batchInfo = Deduction::getBatchInfoByOrderUUId($orderUUId);
        $orderModel = $batchInfo['orderModel'];
        $repairOrderDeduction  = $batchInfo['repairOrderDeduction'];
        $deductionActivity    = $batchInfo['deductionActivity'];
        //$userId = $this->getUserId();
        $clientUserId =  15;//$this->getClientUserId();

        $expireTime = $deductionActivity->expired_time;
        $re = Deduction::canDeduction($repairOrderDeduction, $orderModel, $expireTime);
        if (0 == $re->errCode) {
            $e->canClick = false;
            $e->error = $re->error;
        }
        $checkResult = Deduction::hasClickDeduction($repairOrderDeduction, $orderModel, $clientUserId);
        if (0 == $checkResult->errCode) {
            $e->canClick = false;
            $e->selectedTagId = $checkResult->selectedTag;
            $e->clickResult = Deduction::coverInt($checkResult->clickResult);
            $e->error = $re->error;
        }
        if (isset($deductionActivity['share_img'])) {
            $deductionActivity['share_img'] = ImageManager::getUrl($deductionActivity['share_img']);
        }
        $e->shareTitle = isset($deductionActivity['share_title'])? $deductionActivity['share_title']: '帮我砍价';
        $e->shareImg =  $deductionActivity['share_img'];
        $e->userTagList = Deduction::randomUserTag(9, $e->selectedTagId);
        return $e;
    }

    public function actionSendMina()
    {
        $str = 'M,,';
        $pattern = "/^[A-Z](,[A-Z])+?$/";
        //$pattern = "/^[A-Z]$/";
        $rs = preg_match($pattern, $str);
        print_r($rs);
    }
    public function actionPEngineer()
    {
        //echo Utils::hidePhoneNumber('15622137119');

    }

    public function actionWebSocket()
    {
        $to_uid = "123";
        // 推送的url地址,使用自己的服务器地址
        $push_api_url = "http://192.168.0.106:20211/";
        global $argv;
        $toId = isset($argv[2])?$argv[2]:'';
        $content = isset($argv[3])?$argv[3]:'test ing';

        $newPost = [];
        $newPost['username'] = '张小小';
        $newPost['message'] = $content;

        $post_data = array(
            "type" => "publish",
            "content" => json_encode($newPost),
            "to" => $toId,
        );
        Http::post($push_api_url, $post_data);
    }


    public function actionSub()
    {
        $sTime = time();
        echo "== start time 导入数据 == \r\n";
        $startTime = strtotime('2019-01-01');
        $endTime = strtotime(date('Y-m-d'));
        for ($i = 0 ;$startTime < $endTime ; $i++) {
            if ($i == 29) {
                break;
            }
            $startTime = $startTime + (24 * 3600);
            $isTime = time();
            EngineerTask::archiveAchievement($startTime, false);
            $ieTime = time();
            $sec = $ieTime - $isTime;
            echo "date:".date('Y-m-d', $startTime) .' cost time:'. $sec ."\r\n";
        }

    }


    public function actionSt()
    {
        $orders = $this->getOrdersInfo();
        $prefers = $this->getPreferList();

        $round0 = 0;
        $firstRound = 0;
        $secondRound = 0;
        $thriRound = 0;
        $round4 = 0;
        $round5 = 0;
        $round6 = 0;
        $round7 = 0;
        $dispatchCount = 0;
        $onSiteCount = 0;
        $normalCount = 0;
        foreach ($orders as $k => $order) {
            $engineerIds = $prefers['user_id_'.$order['user_id']];
            $dispatchRecordsModel = RepairOrderDispatchRecords::find();
            $dispatchRecordsModel->where(['repair_order_id' => $order['id'] ]);
            $dispatchRecordsModel->asArray();
            $findResult = $dispatchRecordsModel->all();
            $dispatchCount = $dispatchCount + count($findResult);
            echo $order['id'].'  ccccount:'.count($findResult)."----\r\n";
            if (empty($findResult)) {
                $onSiteCount ++;
            } else {
                $normalCount++;
            }
            if (empty($findResult)) {
                continue;
            }
            $orderFlag = 0;
            foreach ($findResult as $kk => $vv) {
                if (0 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $round0++;
                    $orderFlag = true;
                }
                if (1 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $firstRound++;$orderFlag = true;
                }
                if (2 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $secondRound++;$orderFlag = true;
                }
                if (3 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $thriRound++;$orderFlag = true;
                }
                if (4 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $round4++;$orderFlag = true;
                }
                if (5 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $round5++;$orderFlag = true;
                }
                if (6 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $round6++;$orderFlag = true;
                }
                if (7 == $vv['dispatch_round'] && in_array($vv['engineer_id'], $engineerIds)) {
                    $round7++;$orderFlag = true;
                }
            }
            if (false == $orderFlag ) {
                echo "null:".$order['id']."\r\n";
            }
        }
        echo "dispatchCount:".$dispatchCount."\r\n";
        echo "onSiteCount:".$onSiteCount.' normalCount:'.$normalCount."\r\n";
        echo $round0.'_'.$firstRound.'_'.$secondRound.'_'.$thriRound.'_'.$round4.'_'.$round5.'_'.$round6.'_'.$round7;
    }


    /**
     * 临时提交电子发票申请
     * @return string
     */
    public function actionCreateInvoice()
    {
        $orderModel = RepairOrder::findOne(['order_no' => '201904241505438057' ]);
        if (empty($orderModel)) {
            echo "open invoice fail: repair order is null ";
            return false;
        }
        // 只是开一单一票
        $info = [
            'user_id'   => $orderModel->user_id,
            'type'      => Invoice::HEAD_TYPE_COMPANY,
            'head'      => '深圳市星康科技有限公司',
            'taxpayer_id_number' => '91440300319568546J',
            'email'              => 'perelmen@qq.com',
            'remark'             => '订单号:201904241505438057',
            'register_address'   => '',
            'register_tel'       => '',
            'bank'               => '',
            'bank_account'       => '',
            'amount'             => 329.20,
            'selectOrders'       => [$orderModel->uuid]
        ];
        $result = \domain\trade\Invoice::createInvoice($info);
        echo json_encode($result);
    }

    /**
     * 直接开票,不要用记录到数据库里面,有些商品要开票,直接开票发送总局软件那里,
     * 先发邮件到自己邮箱再发pdf 给客户
     */
    public function actionInvoiceStraight()
    {
        $amount = 20; //开票金额
        $sid = 'sg'.date('YmdHis').mt_rand(1000,9999);
        $customerInfo = array(
            'ghdwsbh'   => '', //公司纳税人识别码
            'ghdwmc'    => '许可', //抬头
            'email'     => 'perelmen@qq.com',
            'ghdwdzdh'  => '', //'购货单位地址、电话'
            'ghdwyhzh'  => '', //'购货单位开户行、银行帐号'
            'bz'        => 'A4纸1箱' //备注
        );
        $serviceInfo = InvoiceApi::getGoodsCode(InvoiceApi::A4_PAPER_INVOICE);
        $queryResult = InvoiceApi::makeOutAnInvoice($sid, $amount, $serviceInfo, $customerInfo);
        var_dump($queryResult);
        sleep(4);
        echo "query1:";
        $queryResult = InvoiceApi::queryInvoice($sid);
        var_dump($queryResult);
        sleep(5);
        echo "query2:";
        $queryResult = InvoiceApi::queryInvoice($sid);
        var_dump($queryResult);
        echo "end";

    }

    public function actionExportD()
    {
        $postId = date('Ymd0001');
        $query = new Query();
        $query->select("repair_order.order_no,repair_order.repair_device_name as device, GROUP_CONCAT(device_fault.`name`) as faults,

                        parent_device_cat.name as keyword,
                        brand.chinese_name as brand");
        $query->from("repair_order_repair_plans");
        $query->leftJoin("repair_order","repair_order.id = repair_order_repair_plans.repair_order_id and repair_order.repair_device_type = 1");
        $query->leftJoin("repair_order_detail","repair_order_detail.repair_order_id = repair_order_repair_plans.repair_order_id and repair_order_detail.pay_at > 0");
        $query->leftJoin("repair_plan","repair_plan.id = repair_order_repair_plans.repair_plan_id");
        $query->leftJoin("device_fault","device_fault.id = repair_plan.device_fault_id");
        $query->leftJoin("engineer_profile","engineer_profile.engineer_id = repair_order.engineer_id");

        $query->leftJoin("user_device","user_device.id = repair_order.repair_device_id");
        $query->leftJoin("device","device.id = user_device.device_id");
        $query->leftJoin("model","model.id = device.model_id");
        $query->leftJoin("brand","brand.id = model.brand_id");
        $query->leftJoin("device_cat","device_cat.id = device.device_cat_id");
        $query->leftJoin("device_cat as parent_device_cat","parent_device_cat.id = device_cat.parent_id");
        $query->where("repair_order.is_system_delete = 0 and repair_order.pay_price > 0 and repair_order.repair_device_type = 1");
        $query->andWhere("repair_order.created_at > UNIX_TIMESTAMP('2019-01-01')");
        //$query->limit(3);
        $query->groupBy("repair_order.order_no");
        $items = $query->all();

        $totalCount = count($items);
        $postItemsTmp = [];
        foreach($items as $k => $item) {
            unset($item['order_no']);
            $key = $item['device'].'_'.$item['faults'].'_'.$item['keyword'].'_'.$item['brand'];
            $postItemsTmp[$key] = $item;
        }
        $postItems = [];
        foreach($postItemsTmp as $k => $vv) {
            $vv['keyword'] = $vv['keyword'].'维修';
            $postItems[] = $vv;
        }

        $dataStr = [
            "items" => $postItems,
            "attribute" => [ "count" => $totalCount, "totalcount" => $totalCount, "id" => $postId, "seq" => 0]
        ];

        $postDataStr = json_encode($dataStr, JSON_UNESCAPED_UNICODE);
        $postDataStr = str_replace('\/', '/', $postDataStr);

        $postData = [
            "data" => $postDataStr,
            "lifespan" => 86400,
            "query" => "{\"type\":1000078}",
            "scene" => 1
        ];
        echo json_encode($postData, JSON_UNESCAPED_UNICODE);

    }

    public function actionTV()
    {
        $repairOrderModel = RepairOrder::find();
        $repairOrderModel->alias('ro');
        $repairOrderModel->select('count(*) as cc,GROUP_CONCAT(ro.created_at) as cr, ro.repair_device_id');
        $repairOrderModel->leftJoin('repair_order_detail rod', 'rod.repair_order_id = ro.id');
        $repairOrderModel->where('ro.repair_device_type = 1 and rod.pay_at >0 and ro.is_system_delete = 0');
        $repairOrderModel->groupBy('ro.repair_device_id');
        $repairOrderModel->having('cc >=2');
        $repairOrderModel->asArray();
        $repairOrderArr = $repairOrderModel->all();
        //print_r($repairOrderArr);
        foreach($repairOrderArr as $k => $order) {
            $timeArr = explode(',', $order['cr']);
            sort($timeArr);
            $timeDuration = [];
            foreach($timeArr as $kk => $vv) {
                if (isset($timeArr[$kk + 1])) {
                    $durationSecond = 0 - ($vv - $timeArr[$kk + 1]);

                    if ($durationSecond<60) {
                        $sDur = $durationSecond. '秒';
                    } elseif($durationSecond >= 60 && $durationSecond < 3600) {
                        $sDur = (round($durationSecond /60, 1)). '分';
                    } elseif($durationSecond >= 3600 && $durationSecond < 86400){
                        $sDur = (round($durationSecond /3600, 1)). '时';
                    } elseif($durationSecond >= 86400 && $durationSecond < 604800) {
                        $sDur = (round($durationSecond /(3600*24), 1)). '天';
                    } else {
                        $sDur = (round($durationSecond /(3600*24*7), 1)). '周';
                    }
                    $timeDuration[] = $sDur;
                }
            }
            $order['durations'] = implode(',', $timeDuration);
            $repairOrderArr[$k] = $order;
            //echo $order['cc'].'_'.$order['repair_device_id'].'_'.$order['durations']."\r\n";
        }

        $arr = [19,39,40];
        sort($arr);
        print_r($arr);

    }

    public function actionSetPostData()
    {
        $str = '';

        $postPackageId = 'D'.date('Ymd').'0000001';
        $postPackage = [
            "lifespan" => 86400,
            "query" => "{\"type\":1000078}",
            "scene" => 1,
            "data"  => "",
        ];

        $packageAttribute = [
                "count" => '',
                "totalcount" => 100,
                "id" => $postPackageId,
                "seq" => 0

        ];

        $index = 0;
        $keywords = ["打印机维修","复印机维修","电脑维修","Mac电脑维修","加碳粉","换墨盒","重装系统","上门维修打印机","上门维修电脑","上门维修复印机","电脑蓝屏","无法使用扫描","打印机无法开机","无法打印","打印效果差","打印卡纸","设备未共享","设备未安装","缺粉","打印颜色淡","打印不清晰","打印模糊","传真或扫描模糊","纸张进纸故障","无法上纸","换主板","换内存","色带用尽","键盘损坏","触摸板失灵","电池鼓包","电池不耐用","无法充电","风扇噪音大","屏幕外壳变形","设备无法开机","无法使用传真","墨水不足","屏幕按键失灵","外壳磨损变形","内屏损坏无显示","闪屏","花屏","碎屏","USB无法使用","上门安装电脑","黑屏","安装软件","安装驱动","无法上网","运行速度慢","忘记系统密码","无法登陆系统","无法连接投影仪","未知故障","复印效果差","无法发送邮件","无法共享打印机","无法打开文件","提示C盘空间不足","办公软件无法使用","无法使用拼音","浏览器无法播放视频","电脑中毒","键盘按键无反应","无法打开office文件","深圳修电脑","深圳修打印机","深圳修复印机","加墨水","福田修电脑","福田修打印机","福田修复印机","修佳能打印机","修惠普打印机","修京瓷打印机","修联想笔记本","修苹果笔记本","修爱普生打印机","喷墨打印机维修","换打印纸","维修三星打印机","针式打印机维修","激光打印机维修","喷墨打印机维修","黑白打印机维修","彩色复印维修","漏墨","复印机闪灯","复印无法联网"];
        $pageList = [];
        foreach($keywords as $k => $v) {
            $pageList[] = ["keyword" => $v];
        }
        $totalcount = count($keywords);
        $postRound = 0;

        //"attribute" => [
        $packageAttribute['count'] = $totalcount;
        $packageAttribute['totalcount'] = $totalcount;
        $packageAttribute['seq'] = $postRound;

        $postPackage['data'] = json_encode(["items" => $pageList, "attribute" => $packageAttribute], JSON_UNESCAPED_UNICODE);
        $postPackage['data'] = str_replace('\/', '/', $postPackage['data']);
        $postWxStr = json_encode($postPackage, JSON_UNESCAPED_UNICODE);
        echo $postWxStr;
        echo "\r\n";
        $minaWechat =  MinaHelper::getWxPHPSDK();
        $result = $minaWechat->setDynamicData($postWxStr);
        print_r($result);
        echo $minaWechat->errCode."\r\n";
        echo $minaWechat->errMsg;
        echo "\r\n";

    }

    /**
     * 贴码补贴发放
     * @return bool
     */
    public function actionPasteAward()
    {
        $bindDeviceApplyFind = BindDeviceApply::find();
        $bindDeviceApplyFind->where("apply_at > UNIX_TIMESTAMP('2019-08-01') and apply_at <= UNIX_TIMESTAMP('2019-08-21') and status = 1 and id = 209227");
        $applyArr = $bindDeviceApplyFind->all();
        foreach ($applyArr as $k => $apply) {
            $engineerModel = Engineer::findOne(['id' => $apply->engineer_id]);
            $result = ApplyAwardRule::canReceivePasteAward($apply, $engineerModel);
            //AppLog::DEBUG('= engineerAddPasteAward =result:'.$result);
            if ($result) {
                $addR = ApplyAwardRule::addPasteAward($apply, strtotime('2019-08-10 00:00:54'));
                return $addR;
            }
        }
    }
    public function actionUserConfirmPrice()
    {
        $orderModel = RepairOrderRepository::findOne(['uuid' => '72c7fd2bb0003bcf8bd55caf3a90ab7b']);
        $userId = $orderModel->user_id;
        $success = PrivateOrderUserOp::confirmPrice($orderModel, $userId, 0, 0);
        echo 'end';
    }

    public function actionClearLog()
    {
        $str = 'OKI 打印机';
        $splitResult = DeviceSearch::splitText($str);
        print_r($splitResult);
    }



}