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
<?php


namespace app\api\controller;

use think\Db;
use app\common\controller\Api;
use function fast\e;

/**
 * 新增接口
 */
class Add extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';


    /**
     * @ApiTitle    (新增电池)
     * @ApiSummary  (新增电池)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/AddBattery)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="battery_code", type="string", required=true, description="电池编号")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    'data':{
    })
     */
    public function AddBattery()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $params = $this->request->param();
        $battery_type_id=Db::name('battery_code')->where('BatteryCode', $params['battery_code'])->value('battery_type_id');
       if(empty($battery_type_id))$this->error('未在产品库找到该电池类型');
        $data = [
            'battery_code' => $params['battery_code'],
            'battery_type_id' => $battery_type_id,
            'stor_id' => $StorID,
            'battery' => 0,
            'status' => 1
        ];
        Db::name('cp')->insert($data);
        $this->success('成功', 1);
    }


    /**
     * @ApiTitle    (故障挂失-根据用户名查询电池型号电池编号)
     * @ApiSummary  (故障挂失-根据用户名查询电池型号电池编号)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/UserSelectBattery)
     * @ApiParams   (name="name", type="string", required=true, description="用户名")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "battery_type_id": 4, //电池类型ID
    "battery_type": "型号4", //电池类型名称
    "BatteryCode": "asdhjghjghjhg"  //电池序列号
    }
    })
     */
    public function UserSelectBattery()
    {
        $Parmas = $this->request->param();
        $Map['h.name'] = ['LIKE', '%' . $Parmas['name'] . '%'];
        $Info = Db::name('hdxxsj')
            ->alias('h')
            ->where($Map)
            ->join('battery_code b', 'b.BatteryCode=h.BatteryCode')
            ->join('battery_type t', 't.id=b.battery_type_id')
            ->field('b.battery_type_id,t.type as battery_type,h.BatteryCode')
            ->find();
        $this->success('成功', $Info);
    }


    /**
     * @ApiTitle    (故障挂失类型)
     * @ApiSummary  (故障挂失类型)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/GuzhangType)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "id": 1,
    "title": "丢失"
    },
    {
    "id": 2,
    "title": "故障"
    },
    {
    "id": 3,
    "title": "人为损坏"
    }
    ]
    })
     */
    public function GuzhangType()
    {
        $Info = [];
        $Info = Db::name('guzhang')->select();
        $this->success('成功', $Info);
    }


    /**
     * @ApiTitle    (故障挂失提交)
     * @ApiSummary  (故障挂失提交)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/GuzhangTables)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="guzhang_id", type="string", required=true, description="故障挂失类型ID")
     * @ApiParams   (name="yydt_yhm", type="string", required=true, description="用户名")
     * @ApiParams   (name="mobile", type="string", required=true, description="手机号")
     * @ApiParams   (name="BatteryCode", type="string", required=true, description="电池序列号")
     * @ApiParams   (name="yydt_zrfd", type="string", required=true, description="责任分担")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    'data':{
    })
     */
    public function GuzhangTables()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $Parmas = $this->request->param();
        $data = [
            'stor_id' => $StorID,
            'guzhang_id' => $Parmas['guzhang_id'],
            'yydt_yhm' => $Parmas['yydt_yhm'],
            'mobile' => $Parmas['mobile'],
            'BatteryCode' => $Parmas['BatteryCode'],
            'yydt_zrfd' => $Parmas['yydt_zrfd'],
            'createtime' => time()
        ];
        $Res = Db::name('gzgs')->insert($data);
        if ($Res) $this->success('提交成功', 1);
        else $this->error('提交失败', 0);
    }


    /**
     * @ApiTitle    (营业状态开关)
     * @ApiSummary  (营业状态开关)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/Tooger)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="status", type="string", required=true, description="0=关闭,1=打开")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    'data':{
    })
     */
    public function Tooger()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $Status = input('status');
        Db::name('stor')->where('id', $StorID)->update(['status' => $Status, 'updatetime' => time()]);
        $this->success('成功', 1);
    }


    /**
     * @ApiTitle    (电池管理)
     * @ApiSummary  (电池管理)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/BatteryList)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "BatteryCenter": [ //充电中
    {
    "battery_type_id": 4,  //电池型号ID
    "num": 1,  //数量
    "BatteryTitle": "型号4" //电池型号名曾
    },
    {
    "battery_type_id": 2,
    "num": 1,
    "BatteryTitle": "型号2"
    }
    ],
    "Clock": [  //锁定
    {
    "battery_type_id": 3,
    "num": 1,
    "BatteryTitle": "型号3"
    },
    {
    "battery_type_id": 1,
    "num": 1,
    "BatteryTitle": "型号1"
    }
    ],
    "BatteryOk": [ //可换电
    {
    "battery_type_id": 3,
    "num": 1,
    "BatteryTitle": "型号3"
    }
    ],
    "About": [ //全部
    {
    "battery_type_id": 4,
    "num": 1,
    "BatteryTitle": "型号4"
    },
    {
    "battery_type_id": 3,
    "num": 2,
    "BatteryTitle": "型号3"
    },
    {
    "battery_type_id": 2,
    "num": 1,
    "BatteryTitle": "型号2"
    },
    {
    "battery_type_id": 1,
    "num": 1,
    "BatteryTitle": "型号1"
    }
    ],
    "Count": 1 //本月换电次数
    }
    })
     */
    public function BatteryList()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        //月
        $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
        $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
        $map['hd_time'] = ['between', [$start_time, $end_time]];

        $data['BatteryCenter'] = [];
        $data['Clock'] = [];
        $data['BatteryOk'] = [];
        $data['About'] = [];
        $data['Count'] = count(Db::name('hdxxsj')->where($map)->where('stor_id', $StorID)->select());
        $data['StorStatus'] = Db::name('stor')->where('id', $StorID)->value('status');
        /*充电中*/
        $data['BatteryCenter'] = Db::name('cp')->where('stor_id', $StorID)->where('status', 1)->field('battery_type_id')->select();
        /*锁定*/
        $data['Clock'] = Db::name('cp')->where('stor_id', $StorID)->where('status', 2)->field('battery_type_id')->select();
        /*可换电*/
        $data['BatteryOk'] = Db::name('cp')->where('stor_id', $StorID)->where('status', 0)->field('battery_type_id')->select();
        /*全部*/
        $data['About'] = Db::name('cp')->where('stor_id', $StorID)->field('battery_type_id')->select();
        if (!empty($data['BatteryCenter'])) {
            $data['BatteryCenter'] = array_values($this->second_array_unique_bykey($data['BatteryCenter'], 'battery_type_id'));
            foreach ($data['BatteryCenter'] as $k => $v) {
                $data['BatteryCenter'][$k]['num'] = count(Db::name('cp')->where('stor_id', $StorID)->where('status', 1)->where('battery_type_id', $v['battery_type_id'])->field('battery_type_id')->select());
                $data['BatteryCenter'][$k]['BatteryTitle'] = Db::name('battery_type')->where('id', $v['battery_type_id'])->value('type');
            }
        }
        if (!empty($data['Clock'])) {
            $data['Clock'] = array_values($this->second_array_unique_bykey($data['Clock'], 'battery_type_id'));
            foreach ($data['Clock'] as $k => $v) {
                $data['Clock'][$k]['num'] = count(Db::name('cp')->where('stor_id', $StorID)->where('status', 2)->where('battery_type_id', $v['battery_type_id'])->field('battery_type_id')->select());
                $data['Clock'][$k]['BatteryTitle'] = Db::name('battery_type')->where('id', $v['battery_type_id'])->value('type');
            }
        }
        if (!empty($data['BatteryOk'])) {
            $data['BatteryOk'] = array_values($this->second_array_unique_bykey($data['BatteryOk'], 'battery_type_id'));
            foreach ($data['BatteryOk'] as $k => $v) {
                $data['BatteryOk'][$k]['num'] = count(Db::name('cp')->where('stor_id', $StorID)->where('status', 0)->where('battery_type_id', $v['battery_type_id'])->field('battery_type_id')->select());
                $data['BatteryOk'][$k]['BatteryTitle'] = Db::name('battery_type')->where('id', $v['battery_type_id'])->value('type');
            }
        }
        if (!empty($data['About'])) {
            $data['About'] = array_values($this->second_array_unique_bykey($data['About'], 'battery_type_id'));
            foreach ($data['About'] as $k => $v) {
                $data['About'][$k]['num'] = count(Db::name('cp')->where('stor_id', $StorID)->where('battery_type_id', $v['battery_type_id'])->field('battery_type_id')->select());
                $data['About'][$k]['BatteryTitle'] = Db::name('battery_type')->where('id', $v['battery_type_id'])->value('type');
            }
        }
        $this->success('成功', $data);
    }


    /**
     * @ApiTitle    (电池管理-充电中)
     * @ApiSummary  (电池管理-充电中)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/BatteryCenter)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="battery_type_id", type="string", required=true, description="电池型号ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "id": 1, //ID
    "battery_code": "asdhjghjghjhg", //电池序列号了
    "Mac": "sdfsdfdsfsdf",  //MAC地址
    "battery": "0" //当前电量
    },
    {
    "id": 4,
    "battery_code": "asdhjghjghjhg",
    "Mac": "sdfsdfdsfsdf",
    "battery": "19"
    }
    ]
    })
     */
    public function BatteryCenter()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $BatteryCenter = [];
        $BatteryCenter = Db::name('cp')
            ->alias('c')
            ->where('c.stor_id', $StorID)
            ->where('c.status', 1)
            ->join('battery_code b', 'b.BatteryCode=c.battery_code')
            ->field('c.id,c.battery_code,b.Mac,c.battery')
            ->select();
        $this->success('成功', $BatteryCenter);
    }


    /**
     * @ApiTitle    (电池管理-锁定)
     * @ApiSummary  (电池管理-锁定)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/BatteryClock)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="battery_type_id", type="string", required=true, description="电池型号ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "id": 3, //ID
    "nickname": "百荣科技 产品经理", //用户
    "type": "型号3" //电池型号
    },
    {
    "id": 5,
    "nickname": "百荣科技 产品经理",
    "type": "型号1"
    }
    ]
    })
     */
    public function BatteryClock()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $BatteryCenter = [];
        $BatteryCenter = Db::name('cp')
            ->alias('c')
            ->where('c.stor_id', $StorID)
            ->where('c.status', 2)
            ->join('battery_type b', 'b.id=c.battery_type_id')
            ->join('user u', 'u.id=c.user_id')
            ->field('c.id,u.nickname,b.type')
            ->select();
        $this->success('成功', $BatteryCenter);
    }


    /**
     * @ApiTitle    (电池管理-全部)
     * @ApiSummary  (电池管理-全部)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/BatteryAbout)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "id": 1, //ID
    "type": "型号4", //电池型号名称
    "battery_code": "asdhjghjghjhg", //电池序列号
    "status": 1 //电池当前状态:0=可使用,1=充电中,2=锁定,3=可充电,4=下架   限制锁定状态不可下架
    },
    {
    "id": 2,
    "type": "型号3",
    "battery_code": "asdhjghjghjhg",
    "status": 0
    },
    {
    "id": 3,
    "type": "型号3",
    "battery_code": "asdhjghjghjhg",
    "status": 2
    },
    {
    "id": 4,
    "type": "型号2",
    "battery_code": "asdhjghjghjhg",
    "status": 1
    },
    {
    "id": 5,
    "type": "型号1",
    "battery_code": "asdhjghjghjhg",
    "status": 2
    }
    ]
    })
     */
    public function BatteryAbout()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $BatteryAbout = [];
        $BatteryAbout = Db::name('cp')
            ->alias('c')
            ->where('c.stor_id', $StorID)
            ->join('battery_type b', 'b.id=c.battery_type_id')
            ->field('c.id,b.type,c.battery_code,c.status')
            ->select();
        $this->success('成功', $BatteryAbout);
    }


    /**
     * @ApiTitle    (电池管理-可换电)
     * @ApiSummary  (电池管理-可换电)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/BatteryOk)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "id": 1, //ID
    "type": "型号4", //电池型号名称
    "battery_code": "asdhjghjghjhg", //电池序列号
    "status": 1 //电池当前状态:0=可使用,1=充电中,2=锁定,3=可充电,4=下架   限制锁定状态不可下架
    }
    ]
    })
     */
    public function BatteryOk()
    {
        $UserId = $this->IsToken($this->request->header());
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $BatteryAbout = [];
        $BatteryAbout = Db::name('cp')
            ->alias('c')
            ->where('c.stor_id', $StorID)
            ->where('c.status', 0)
            ->join('battery_type b', 'b.id=c.battery_type_id')
            ->field('c.id,b.type,c.battery_code,c.status')
            ->select();
        $this->success('成功', $BatteryAbout);
    }


    /**
     * @ApiTitle    (紧急使用)
     * @ApiSummary  (紧急使用)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/JInji)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", required=true, description="数据行ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    })
     */
    public function JInji()
    {
        $UserId = $this->IsToken($this->request->header());
        $Id = input('id');
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $Res = Db::name('cp')->where('stor_id', $StorID)->where('id', $Id)->update(['status' => 0]);
        if ($Res) $this->success('成功', 1);
        else $this->error('失败', 0);
    }


    /**
     * @ApiTitle    (下架电池)
     * @ApiSummary  (下架电池)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/Xiajia)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", required=true, description="数据行ID")
     * @ApiParams   (name="status", type="string", required=true, description="操作 0=上架,4=下架")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    })
     */
    public function Xiajia()
    {
        $UserId = $this->IsToken($this->request->header());
        $Parmas = $this->request->param();
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $Res = Db::name('cp')->where('stod_id', $StorID)->where('id', $Parmas['id'])->update(['status' => $Parmas['status']]);
        if ($Res) $this->success('成功', 1);
        else $this->error('失败', 0);
    }


    /**
     * @ApiTitle    (选择电池页面)
     * @ApiSummary  (选择电池页面)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/OtherBatteryList)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", required=true, description="数据行ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "battery_id": 2, //ID  发放电池请求使用
    "battery_code": "asdhjghjghjhg" //电池序列号
    },
    {
    "battery_id": 5,
    "battery_code": "asdhjghjghjhg"
    }
    ]
    })
     */
    public function OtherBatteryList()
    {
        $UserId = $this->IsToken($this->request->header());
        $Parmas = $this->request->param();
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        //'battery_type_id'
        $BatteryType_Id = Db::name('cp')->where('id', $Parmas['id'])->find();
        $Map1['status'] = ['EQ', 0];
        $Map2['id'] = ['EQ', $Parmas['id']];
        $Info = Db::name('cp')->where('stor_id', $StorID)->where($Map1)->where('battery_type_id', $BatteryType_Id['battery_type_id'])->field('id as battery_id,battery_code')->select();
        $Info2 = Db::name('cp')->where('stor_id', $StorID)->where($Map2)->where('battery_type_id', $BatteryType_Id['battery_type_id'])->field('id as battery_id,battery_code')->select();
        $this->success('成功', array_values(array_merge($Info, $Info2)));
    }


    /**
     * @ApiTitle    (发放电池)
     * @ApiSummary  (发放电池)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Add/OutBattery)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", required=true, description="数据行ID")
     * @ApiParams   (name="battery_id", type="string", required=true, description="选择的电池ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    })
     */
    public function OutBattery()
    {
        $UserId = $this->IsToken($this->request->header());
        $Parmas = $this->request->param();
        $mobile = Db::name('user')->where('id', $UserId)->value('mobile');
        $StorID = Db::name('stor')->where('mobile', $mobile)->value('id');
        if (empty($StorID)) {
            $this->error('您不是门店拥有者');
        }
        $Con = Db::name('cp')->where('id', $Parmas['id'])->find();
        Db::name('cp')->where('id', $Parmas['id'])->update(['status' => 0, 'user_id' => '']);
        Db::name('cp')->where('id', $Parmas['battery_id'])->delete();
        $data = [
            'user_id' => $Con['user_id'],
            'stor_id' => $StorID,
            'name' => Db::name('user')->where('id', $Con['user_id'])->value('nickname'),
            'hd_time' => time(),
            'BatteryCode' => $Con['battery_code']
        ];
        Db::name('hdxxsj')->insert($data);
        $this->success('发放成功', 1);
    }
}