|
|
<?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();
|
|
|
$data = [
|
|
|
'battery_code' => $params['battery_code'],
|
|
|
'battery_type_id' => Db::name('battery_code')->where('BatteryCode', $params['battery_code'])->value('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['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('stod_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);
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|