Commit 2aba8468 by xj

Merge branch 'master' of git.senthink.com:yangsh/cdz_pay_v2

parents d783e8bf a656beef
No preview for this file type
...@@ -1455,7 +1455,7 @@ namespace Illuminate\Support\Facades { ...@@ -1455,7 +1455,7 @@ namespace Illuminate\Support\Facades {
} }
/** /**
* Run an update statement against the database. * Run an Update statement against the database.
* *
* @param string $query * @param string $query
* @param array $bindings * @param array $bindings
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/9
* Time: 下午7:00
*/
namespace App\Console\Commands\sync;
use Illuminate\Console\Command;
use DB;
class SyncPortFromStaging extends Command
{
protected $signature = 'sync:port_staging';
protected $description = '从staging环境同步网管口子';
/**
*
*/
public function handle()
{
$devices = DB::connection('old_cdz')->table('devices')->where('gateway_id', 1)->get()->toArray();
dd($devices);
return;
foreach ($devices as $device) {
if (DB::table('devices')->where('device_mac', $device['device_mac'])->exists() === false) {
DB::table('devices')->insert([
'device_mac' => $device['device_mac'],
'name' => $device['name'],
'gateway_id' => 9,
'station_id' => 5,
'created_at' => date('Y-m-d H:i:s'),
'type' => 1,
]);
}
}
}
}
\ No newline at end of file
...@@ -10,9 +10,10 @@ namespace App\Console\Commands\timer; ...@@ -10,9 +10,10 @@ namespace App\Console\Commands\timer;
use App\Model\LogGatewayModel; use App\Model\LogGatewayModel;
use Carbon\Carbon;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use DB; use DB;
use Lib\cdz_order\Order;
use Lib\gateway\port\Port;
use Lib\redis\RedisSingle; use Lib\redis\RedisSingle;
use Log; use Log;
...@@ -26,18 +27,78 @@ class ScanOrderFinish extends Command ...@@ -26,18 +27,78 @@ class ScanOrderFinish extends Command
*/ */
protected $description = '定时器扫描订单是否已过时'; protected $description = '定时器扫描订单是否已过时';
private function scanf()
{
$date = date('Y-m-d H:i:s');
$expireOrders = DB::table('wx_charger_orders')->where('state', -1)->get(['start_time', 'charger_time', 'id', 'port_id', 'station_id', 'gateway_id']);
$redis = RedisSingle::getRedis();
$time = time();
$redis->multi(2);
$redis = RedisSingle::getRedis();
$order = new Order();
foreach ($expireOrders as $expireOrder) {
echo $expireOrder->id . PHP_EOL;
$order->setId($expireOrder->id);
$cache = $order->getOrderCache($redis);
if ($cache === false) {
$startTime = strtotime($expireOrder->start_time);
} else {
$startTime = $cache['startTime'];
}
if (($time - $startTime) > ($expireOrder->charger_time * 60 + 60 * 5)) {
Log::debug($expireOrder->id);
Log::debug($startTime);
$result = DB::table('wx_charger_orders')->where('id', $expireOrder->id)->update([
'end_time' => date('Y-m-d H:i:s', strtotime($expireOrder->start_time) + $expireOrder->charger_time * 60),
'updated_at' => $date,
'state' => 3,
'is_stop' => 46,
]);
DB::table('gateway_log')->insert([
'gateway_id' => $expireOrder->gateway_id,
'station_id' => $expireOrder->station_id,
'port_id' => $expireOrder->port_id,
'order_id' => $expireOrder->id,
'type' => 1,
'desc' => '系统自动结束订单',
'command' => 'ff'
]);
$redis->hDel('cdz:port:using:order_id:hash', $expireOrder->port_id);
$redis->zRem('cdz:port:using:user_id:zset', $expireOrder->port_id);
$redis->del('cdz:order:state:' . $expireOrder->id);
}
}
$redis->exec();
}
public function handle() public function handle()
{ {
$date = date('Y-m-d H:i:s'); $date = date('Y-m-d H:i:s');
$this->info($date);
$expireOrders = DB::table('wx_charger_orders')->where([ $expireOrders = DB::table('wx_charger_orders')->where([
['is_charger', '12'],//开始充电 ['is_charger', '12'],//开始充电
['end_time', null],//没有结束时间 ['end_time', null],//没有结束时间
['state', '<>', 3],//没有退款 ['state', '<>', 3],//没有退款
['state' . '<>', 4],
['state', '<>', 1],//订单未结束 ['state', '<>', 1],//订单未结束
])->whereDate('created_at', '=', date('Y-m-d'))->get(['start_time', 'charger_time', 'id', 'port_id', 'station_id', 'gateway_id']); ])->whereDate('created_at', '=', date('Y-m-d'))->get(['start_time', 'charger_time', 'id', 'port_id', 'station_id', 'gateway_id']);
...@@ -45,18 +106,28 @@ class ScanOrderFinish extends Command ...@@ -45,18 +106,28 @@ class ScanOrderFinish extends Command
$time = time(); $time = time();
$redis = RedisSingle::getRedis(); $redis = RedisSingle::getRedis();
$order = new Order();
$redis->multi(2); $port = new Port();
foreach ($expireOrders as $expireOrder) { foreach ($expireOrders as $expireOrder) {
echo $expireOrder->id . PHP_EOL;
$order->setId($expireOrder->id);
$cache = $order->getOrderCache($redis);
if ($cache === false) {
$startTime = strtotime($expireOrder->start_time);
} else {
$startTime = $cache['startTime'];
if ($time > strtotime($expireOrder->start_time) + $expireOrder->charger_time * 60 + 60 * 5) { }
if (($time - $startTime) > ($expireOrder->charger_time * 60 + 60 * 5)) {
Log::debug(($time - $startTime));
Log::debug(($expireOrders->charger_time * 60 + 60 * 5));
Log::debug('expired order', [$expireOrder->id, $startTime]);
$result = DB::table('wx_charger_orders')->where('id', $expireOrder->id)->update([ $result = DB::table('wx_charger_orders')->where('id', $expireOrder->id)->update([
'end_time' => date('Y-m-d H:i:s', strtotime($expireOrder->start_time) + $expireOrder->charger_time * 60), 'end_time' => date('Y-m-d H:i:s'),
'updated_at' => $date, 'updated_at' => $date,
'state' => 3, 'state' => 4,
'is_stop' => 46, 'is_stop' => 46,
]); ]);
...@@ -75,16 +146,19 @@ class ScanOrderFinish extends Command ...@@ -75,16 +146,19 @@ class ScanOrderFinish extends Command
$redis->del('cdz:order:state:' . $expireOrder->id); $redis->del('cdz:order:state:' . $expireOrder->id);
$port->setPortId($expireOrder->port_id);
$state = $port->getState($redis, $expireOrder->port_id);
if ($state === 12) {
$port->setState(11);
}
} }
} }
$redis->exec(); // $redis->exec();
Log::info('update expired orders'); Log::info('Update expired orders');
} }
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/28
* Time: 下午1:58
*/
namespace App\Console\Commands\update;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Sign extends Command
{
protected $signature = 'Update:sign';
protected $description = 'ota文件md5签名';
public function handle()
{
$updateFiles = DB::table('gateway_update')->get(['hardware_version', 'software_version', 'id']);
foreach ($updateFiles as $file) {
// $fileName = $file['hardware_version'] . $file['software_version'];
$fileName = $file->hardware_version . $file->software_version;
$sign = md5_file(base_path() . '/public/Update/' . $fileName . '.bin');
DB::table('gateway_update')->where('id', $file->id)->update([
'sign' => strtoupper($sign)
]);
}
}
}
\ No newline at end of file
...@@ -9,10 +9,12 @@ use App\Console\Commands\MenuSetting; ...@@ -9,10 +9,12 @@ use App\Console\Commands\MenuSetting;
use App\Console\Commands\RedisCommand; use App\Console\Commands\RedisCommand;
use App\Console\Commands\sync\Port; use App\Console\Commands\sync\Port;
use App\Console\Commands\sync\Station; use App\Console\Commands\sync\Station;
use App\Console\Commands\sync\SyncPortFromStaging;
use App\Console\Commands\sync\SyncWxUserOpenIdCommand; use App\Console\Commands\sync\SyncWxUserOpenIdCommand;
use App\Console\Commands\SyncStationFrequency; use App\Console\Commands\SyncStationFrequency;
use App\Console\Commands\TestPortCommand; use App\Console\Commands\TestPortCommand;
use App\Console\Commands\timer\ScanOrderFinish; use App\Console\Commands\timer\ScanOrderFinish;
use App\Console\Commands\update\Sign;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel; use Laravel\Lumen\Console\Kernel as ConsoleKernel;
...@@ -36,6 +38,8 @@ class Kernel extends ConsoleKernel ...@@ -36,6 +38,8 @@ class Kernel extends ConsoleKernel
AddImg::class, AddImg::class,
ScanOrderFinish::class, ScanOrderFinish::class,
Create::class, Create::class,
Sign::class,
SyncPortFromStaging::class
]; ];
/** /**
......
...@@ -10,6 +10,7 @@ namespace App\Http\Controllers\V1\Charger; ...@@ -10,6 +10,7 @@ namespace App\Http\Controllers\V1\Charger;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Model\PortModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Lib\balance\BalanceOrder; use Lib\balance\BalanceOrder;
use Lib\balance\charger\HandleClient; use Lib\balance\charger\HandleClient;
...@@ -49,7 +50,7 @@ class BalanceController extends Controller ...@@ -49,7 +50,7 @@ class BalanceController extends Controller
'pay_amount' => 'required|numeric', 'pay_amount' => 'required|numeric',
'time' => 'required|integer', 'time' => 'required|integer',
'port_id' => 'required|exists:devices,id', 'port_id' => 'required|exists:devices,id|',
'station_id' => 'required|exists:stations,id', 'station_id' => 'required|exists:stations,id',
'charger_type' => 'required|integer', 'charger_type' => 'required|integer',
'station_name' => 'required', 'station_name' => 'required',
...@@ -65,6 +66,14 @@ class BalanceController extends Controller ...@@ -65,6 +66,14 @@ class BalanceController extends Controller
$portId = $request->get('port_id'); $portId = $request->get('port_id');
$portModel = PortModel::where('id', $portId)->first(['status_id', 'type_id']);
if ($portModel->status_id === 8) {
abort(400, '口子被禁用');
}
$station->setStationId($stationId); $station->setStationId($stationId);
$payTemplate = json_decode($station->getPayTemplate(), true); $payTemplate = json_decode($station->getPayTemplate(), true);
...@@ -115,6 +124,8 @@ class BalanceController extends Controller ...@@ -115,6 +124,8 @@ class BalanceController extends Controller
$balanceOrder = new BalanceOrder(); $balanceOrder = new BalanceOrder();
$balanceOrder->setTypeId($portModel->type_id);
$balanceOrder->setStation($station); $balanceOrder->setStation($station);
$balanceOrder->setUserId($user->id); $balanceOrder->setUserId($user->id);
......
...@@ -58,10 +58,15 @@ class ChangePortController extends Controller ...@@ -58,10 +58,15 @@ class ChangePortController extends Controller
$newState = $port->getState(RedisSingle::getRedis(), $newPortId); $newState = $port->getState(RedisSingle::getRedis(), $newPortId);
if ($newState != 11) { if ($newState != 11) {
abort(400, '更换口子非空闲状态'); abort(400, '更换口子非空闲状态');
} }
$result = true;
if ($orderCollection->state === 3) { if ($orderCollection->state === 3) {
Log::debug('以退款'); Log::debug('以退款');
...@@ -69,8 +74,24 @@ class ChangePortController extends Controller ...@@ -69,8 +74,24 @@ class ChangePortController extends Controller
$this->resultMessage = '订单已退款'; $this->resultMessage = '订单已退款';
$result = false;
} else if ($orderCollection->is_charger !== -1) { } else if ($orderCollection->is_charger !== -1) {
$order = new Order();
$order->setId($orderId);
if ($order->getOrderCache(RedisSingle::getRedis()) != false) {
if ($order->getStateCode() != -1) {
$result = false;
} else {
DB::table('wx_charger_orders')->where('id', $orderId)->update([
'start_time' => null,
'is_charger' => -1,
]);
}
}
$this->resultCode = 'FAIL'; $this->resultCode = 'FAIL';
$this->resultMessage = '订单消费中,无法更换端口'; $this->resultMessage = '订单消费中,无法更换端口';
...@@ -79,9 +100,16 @@ class ChangePortController extends Controller ...@@ -79,9 +100,16 @@ class ChangePortController extends Controller
$this->resultCode = 'FAIL'; $this->resultCode = 'FAIL';
$result = false;
$this->resultMessage = '最多只能更换口子3次'; $this->resultMessage = '最多只能更换口子3次';
} else { }
if ($result === false) {
return $this->response->array($this->getResponseCode());
}
// 发送结束充电命令至端口,发送开始充电命令给新端口,修改订单表中的数据 // 发送结束充电命令至端口,发送开始充电命令给新端口,修改订单表中的数据
...@@ -242,12 +270,12 @@ class ChangePortController extends Controller ...@@ -242,12 +270,12 @@ class ChangePortController extends Controller
'port_name' => $request->get('new_port_name'), 'port_name' => $request->get('new_port_name'),
'gateway_id' => $newGatewayId, 'gateway_id' => $newGatewayId,
'change_times' => DB::raw('change_times + 1'), 'change_times' => DB::raw('change_times + 1'),
'start_time' => null,
'is_charger' => -1,
]); ]);
}
return $this->response->array($this->getResponseCode()); return $this->response->array($this->getResponseCode());
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 下午3:41
*/
namespace App\Http\Controllers\V1\Update;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Lib\send\command\UpdateCommand;
use Lib\send\Send;
use Validator;
use DB;
use Log;
class UpdateController extends Controller
{
public function noticeUpdate(Request $request)
{
$validator = Validator::make($request->all(), [
'gateway_mac' => 'required|exists:gateways,mac_address',
'download_url' => 'required',
'hardware' => 'required',
'software' => 'required',
'time' => 'required',
]);
if ($validator->fails() === true) {
abort(400, $validator->errors()->first());
}
$updateTime = $request->get('time');
$gatewayMac = $request->get('gateway_mac');
$downloadUrl = $request->get('download_url');
$hardwareVersion = $request->get('hardware');
$softwareVersion = $request->get('software');
$updateCommand = new UpdateCommand($gatewayMac);
$updateCommand->setSoftware($softwareVersion);
$updateCommand->setHardware($hardwareVersion);
$updateCommand->setDownloadUrl($downloadUrl);
$updateCommand->setUpdateTime($updateTime);
$send = new Send($updateCommand);
if ($send->send() === true) {
return $this->response->array($this->getResponseCode());
} else {
$this->resultCode = 'FAIL';
$this->resultMessage = '发送失败或设备不在线';
return $this->response->array($this->getResponseCode());
}
}
public function upload(Request $request)
{
Log::debug($request->all());
$validator = Validator::make($request->all(), [
'hardware' => 'required',
'software' => 'required',
'type' => 'required|exists:gateway_types,id',
]);
if ($validator->fails() === true) {
Log::debug('error');
return $this->response->array(['msg' => $validator->errors()->first(), 'code' => 'FAIL']);
}
if ($request->file('firmware')->isValid() === false) {
return $this->response->array(['msg' => 'miss file', 'code' => 'FAIL']);
}
$hardware = $request->get('hardware');
$software = $request->get('software');
$fileName = $hardware . $software . '.bin';
$gatewayType = $request->get('type');
$date = date('Y-m-d H:i:s');
$file = $request->file('firmware')->move(base_path() . '/public/update', $fileName);
Log::debug(base_path('/public/update/' . $fileName));
$sign = md5_file(base_path('/public/update/' . $fileName));
if (DB::table('gateway_update')->where(['gateway_type' => $gatewayType])->exists() === true) {
DB::table('gateway_update')->where(['gateway_type' => $gatewayType])->update([
'hardware_version' => strtoupper($hardware),
'software_version' => strtoupper($software),
'updated_at' => $date,
'sign' => strtoupper($sign),
]);
} else {
DB::table('gateway_update')->insert([
'hardware_version' => strtoupper($hardware),
'software_version' => strtoupper($software),
'updated_at' => $date,
'sign' => strtoupper($sign),
'created_at' => $date,
'gateway_type' => $gatewayType,
]);
}
return $this->response->array(['code' => 'SUCCESS']);
}
}
\ No newline at end of file
...@@ -63,12 +63,8 @@ class StatisticController extends Controller ...@@ -63,12 +63,8 @@ class StatisticController extends Controller
$portsId = $userUsingOrder->getUserUsingPortId();//获取用户正在使用的口子id $portsId = $userUsingOrder->getUserUsingPortId();//获取用户正在使用的口子id
Log::debug($portsId);
$orderIds = $userUsingOrder->getPortsOrderId($portsId); $orderIds = $userUsingOrder->getPortsOrderId($portsId);
Log::debug($orderIds);
if ($orderIds === false) { if ($orderIds === false) {
$orderIds = []; $orderIds = [];
...@@ -86,8 +82,7 @@ class StatisticController extends Controller ...@@ -86,8 +82,7 @@ class StatisticController extends Controller
$tmp = $adaptor->adaptor(); $tmp = $adaptor->adaptor();
if($tmp !== false) if ($tmp !== false) {
{
array_push($ordersState, $tmp); array_push($ordersState, $tmp);
} }
...@@ -104,7 +99,7 @@ class StatisticController extends Controller ...@@ -104,7 +99,7 @@ class StatisticController extends Controller
$createdAt = strtotime($value['created_at']); $createdAt = strtotime($value['created_at']);
return $createdAt + $chargerTime * 60 > time(); return $createdAt + $chargerTime * 60 + 1 * 60 > time();
});//剔除充电结束的订单 });//剔除充电结束的订单
......
...@@ -39,6 +39,7 @@ class AccessController extends Controller ...@@ -39,6 +39,7 @@ class AccessController extends Controller
public function getUserInfo(Request $request, WebGrant $wxWebGrant) public function getUserInfo(Request $request, WebGrant $wxWebGrant)
{ {
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'code' => 'required', 'code' => 'required',
...@@ -46,7 +47,7 @@ class AccessController extends Controller ...@@ -46,7 +47,7 @@ class AccessController extends Controller
if ($validator->fails()) { if ($validator->fails()) {
abort(400); abort(400, $validator->errors()->first());
} }
...@@ -78,6 +79,8 @@ class AccessController extends Controller ...@@ -78,6 +79,8 @@ class AccessController extends Controller
if (!$wxUserModel->addUser($wxUser)) { if (!$wxUserModel->addUser($wxUser)) {
Log::error('add user fail');
abort(500, 'database store error'); abort(500, 'database store error');
} }
...@@ -103,7 +106,8 @@ class AccessController extends Controller ...@@ -103,7 +106,8 @@ class AccessController extends Controller
return $this->response->array($this->getResponseCode() + ['data' => [ return $this->response->array($this->getResponseCode() + ['data' => [
'token' => $token, 'token' => $token,
]]); ]
]);
} catch (\Exception $exception) { } catch (\Exception $exception) {
Log::error($exception->getMessage()); Log::error($exception->getMessage());
......
...@@ -10,6 +10,7 @@ namespace App\Http\Controllers\V1\Wx; ...@@ -10,6 +10,7 @@ namespace App\Http\Controllers\V1\Wx;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Model\PortModel;
use Lib\gateway\Gateway; use Lib\gateway\Gateway;
use Lib\gateway\port\Port; use Lib\gateway\port\Port;
use Lib\order_exception\OrderTrace; use Lib\order_exception\OrderTrace;
...@@ -50,13 +51,12 @@ class PayController extends Controller ...@@ -50,13 +51,12 @@ class PayController extends Controller
{ {
//todo 验证条件添加
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'station_id' => 'required|exists:stations,id', 'station_id' => 'required|exists:stations,id',
'port_id' => 'required', 'port_id' => 'required',
'amount' => 'required|numeric', 'amount' => 'required|numeric',
// 'time' => 'required|integer', // 'time' => 'required|integer',
'charger_type' => 'required|integer', 'charger_type' => 'required|integer',
]); ]);
...@@ -68,6 +68,13 @@ class PayController extends Controller ...@@ -68,6 +68,13 @@ class PayController extends Controller
$portId = $request->get('port_id'); $portId = $request->get('port_id');
$portModel = PortModel::where('id', $portId)->first(['status_id']);
if ($portModel->status_id === 8) {
abort(400, '口子被禁用');
}
$port->setPortId($portId); $port->setPortId($portId);
$gatewayId = $port->getGatewayId(); $gatewayId = $port->getGatewayId();
......
...@@ -38,8 +38,9 @@ $app->configure('auth'); ...@@ -38,8 +38,9 @@ $app->configure('auth');
$app->configure('database'); $app->configure('database');
$app->withFacades(); $app->configure('iot');
$app->withFacades();
$app->withEloquent(); $app->withEloquent();
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午10:34
*/
return [
'cert_path' => storage_path('cert/key.pem'),
'password' => 'IoM@1234',
'host' => 'https://180.101.147.89:8743/',
'app_key' => 'tWVEY6ruJIYnQ1XdadMZHU9IR0sa',
];
...@@ -1504,7 +1504,7 @@ class Connection ...@@ -1504,7 +1504,7 @@ class Connection
$this->indentCsv(array_values($this->col_values)) . ')'; $this->indentCsv(array_values($this->col_values)) . ')';
} }
// ------update------- // ------Update-------
/** /**
* 更新哪个表 * 更新哪个表
* *
...@@ -1835,7 +1835,7 @@ class Connection ...@@ -1835,7 +1835,7 @@ class Connection
$statement = strtolower(trim($rawStatement[0])); $statement = strtolower(trim($rawStatement[0]));
if ($statement === 'select' || $statement === 'show') { if ($statement === 'select' || $statement === 'show') {
return $this->sQuery->fetchAll($fetchmode); return $this->sQuery->fetchAll($fetchmode);
} elseif ($statement === 'update' || $statement === 'delete') { } elseif ($statement === 'Update' || $statement === 'delete') {
return $this->sQuery->rowCount(); return $this->sQuery->rowCount();
} elseif ($statement === 'insert') { } elseif ($statement === 'insert') {
if ($this->sQuery->rowCount() > 0) { if ($this->sQuery->rowCount() > 0) {
......
...@@ -1070,7 +1070,7 @@ class YourClient extends \Guzzle\Service\Client ...@@ -1070,7 +1070,7 @@ class YourClient extends \Guzzle\Service\Client
"parameters":{ "parameters":{
"id": { "id": {
"location": "uri", "location": "uri",
"description":"Group to update by ID", "description":Update,
"type": "integer", "type": "integer",
"required": true "required": true
}, },
......
...@@ -412,7 +412,7 @@ class Connection implements ConnectionInterface ...@@ -412,7 +412,7 @@ class Connection implements ConnectionInterface
} }
/** /**
* Run an update statement against the database. * Run an Update statement against the database.
* *
* @param string $query * @param string $query
* @param array $bindings * @param array $bindings
...@@ -473,7 +473,7 @@ class Connection implements ConnectionInterface ...@@ -473,7 +473,7 @@ class Connection implements ConnectionInterface
return 0; return 0;
} }
// For update or delete statements, we want to get the number of rows affected // For Update or delete statements, we want to get the number of rows affected
// by the statement and return that back to the developer. We'll first need // by the statement and return that back to the developer. We'll first need
// to execute the statement and then we'll use PDO to fetch the affected. // to execute the statement and then we'll use PDO to fetch the affected.
$statement = $this->getPdo()->prepare($query); $statement = $this->getPdo()->prepare($query);
......
...@@ -50,7 +50,7 @@ interface ConnectionInterface ...@@ -50,7 +50,7 @@ interface ConnectionInterface
public function insert($query, $bindings = []); public function insert($query, $bindings = []);
/** /**
* Run an update statement against the database. * Run an Update statement against the database.
* *
* @param string $query * @param string $query
* @param array $bindings * @param array $bindings
......
...@@ -384,7 +384,7 @@ class Builder ...@@ -384,7 +384,7 @@ class Builder
} }
/** /**
* Create or update a record matching the attributes, and fill it with values. * Create or Update a record matching the attributes, and fill it with values.
* *
* @param array $attributes * @param array $attributes
* @param array $values * @param array $values
......
...@@ -14,7 +14,7 @@ trait HasTimestamps ...@@ -14,7 +14,7 @@ trait HasTimestamps
public $timestamps = true; public $timestamps = true;
/** /**
* Update the model's update timestamp. * Update the model's Update timestamp.
* *
* @return bool * @return bool
*/ */
...@@ -30,7 +30,7 @@ trait HasTimestamps ...@@ -30,7 +30,7 @@ trait HasTimestamps
} }
/** /**
* Update the creation and update timestamps. * Update the creation and Update timestamps.
* *
* @return void * @return void
*/ */
......
...@@ -539,9 +539,9 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab ...@@ -539,9 +539,9 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
return false; return false;
} }
// If the model already exists in the database we can just update our record // If the model already exists in the database we can just Update our record
// that is already in this database using the current IDs in this "where" // that is already in this database using the current IDs in this "where"
// clause to only update this model. Otherwise, we'll just insert them. // clause to only Update this model. Otherwise, we'll just insert them.
if ($this->exists) { if ($this->exists) {
$saved = $this->isDirty() ? $saved = $this->isDirty() ?
$this->performUpdate($query) : true; $this->performUpdate($query) : true;
...@@ -602,28 +602,28 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab ...@@ -602,28 +602,28 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
} }
/** /**
* Perform a model update operation. * Perform a model Update operation.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @return bool * @return bool
*/ */
protected function performUpdate(Builder $query) protected function performUpdate(Builder $query)
{ {
// If the updating event returns false, we will cancel the update operation so // If the updating event returns false, we will cancel the Update operation so
// developers can hook Validation systems into their models and cancel this // developers can hook Validation systems into their models and cancel this
// operation if the model does not pass validation. Otherwise, we update. // operation if the model does not pass validation. Otherwise, we Update.
if ($this->fireModelEvent('updating') === false) { if ($this->fireModelEvent('updating') === false) {
return false; return false;
} }
// First we need to create a fresh query instance and touch the creation and // First we need to create a fresh query instance and touch the creation and
// update timestamp on the model which are maintained by us for developer // Update timestamp on the model which are maintained by us for developer
// convenience. Then we will just continue saving the model instances. // convenience. Then we will just continue saving the model instances.
if ($this->usesTimestamps()) { if ($this->usesTimestamps()) {
$this->updateTimestamps(); $this->updateTimestamps();
} }
// Once we have run the update operation, we will fire the "updated" event for // Once we have run the Update operation, we will fire the "updated" event for
// this model instance. This will allow developers to hook into these after // this model instance. This will allow developers to hook into these after
// models are updated, giving them a chance to do any special processing. // models are updated, giving them a chance to do any special processing.
$dirty = $this->getDirty(); $dirty = $this->getDirty();
...@@ -640,7 +640,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab ...@@ -640,7 +640,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
} }
/** /**
* Set the keys for a save update query. * Set the keys for a save Update query.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
...@@ -676,7 +676,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab ...@@ -676,7 +676,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
} }
// First we'll need to create a fresh query instance and touch the creation and // First we'll need to create a fresh query instance and touch the creation and
// update timestamps on this model, which are maintained by us for developer // Update timestamps on this model, which are maintained by us for developer
// convenience. After, we will just continue saving these model instances. // convenience. After, we will just continue saving these model instances.
if ($this->usesTimestamps()) { if ($this->usesTimestamps()) {
$this->updateTimestamps(); $this->updateTimestamps();
...@@ -703,8 +703,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab ...@@ -703,8 +703,8 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
} }
// We will go ahead and set the exists property to true, so that it is set when // We will go ahead and set the exists property to true, so that it is set when
// the created event is fired, just in case the developer tries to update it // the created event is fired, just in case the developer tries to Update it
// during the event. This will allow them to do so and run an update here. // during the event. This will allow them to do so and run an Update here.
$this->exists = true; $this->exists = true;
$this->wasRecentlyCreated = true; $this->wasRecentlyCreated = true;
......
...@@ -444,7 +444,7 @@ class BelongsToMany extends Relation ...@@ -444,7 +444,7 @@ class BelongsToMany extends Relation
} }
/** /**
* Create or update a related record matching the attributes, and fill it with values. * Create or Update a related record matching the attributes, and fill it with values.
* *
* @param array $attributes * @param array $attributes
* @param array $values * @param array $values
...@@ -766,7 +766,7 @@ class BelongsToMany extends Relation ...@@ -766,7 +766,7 @@ class BelongsToMany extends Relation
$this->related->getUpdatedAtColumn() => $this->related->freshTimestampString(), $this->related->getUpdatedAtColumn() => $this->related->freshTimestampString(),
]; ];
// If we actually have IDs for the relation, we will run the query to update all // If we actually have IDs for the relation, we will run the query to Update all
// the related model's timestamps, to make sure these all reflect the changes // the related model's timestamps, to make sure these all reflect the changes
// to the parent models. This will help us keep any caching synced up here. // to the parent models. This will help us keep any caching synced up here.
if (count($ids = $this->allRelatedIds()) > 0) { if (count($ids = $this->allRelatedIds()) > 0) {
...@@ -922,7 +922,7 @@ class BelongsToMany extends Relation ...@@ -922,7 +922,7 @@ class BelongsToMany extends Relation
} }
/** /**
* Specify that the pivot table has creation and update timestamps. * Specify that the pivot table has creation and Update timestamps.
* *
* @param mixed $createdAt * @param mixed $createdAt
* @param mixed $updatedAt * @param mixed $updatedAt
......
...@@ -154,15 +154,15 @@ trait InteractsWithPivotTable ...@@ -154,15 +154,15 @@ trait InteractsWithPivotTable
foreach ($records as $id => $attributes) { foreach ($records as $id => $attributes) {
// If the ID is not in the list of existing pivot IDs, we will insert a new pivot // If the ID is not in the list of existing pivot IDs, we will insert a new pivot
// record, otherwise, we will just update this existing record on this joining // record, otherwise, we will just Update this existing record on this joining
// table, so that the developers will easily update these records pain free. // table, so that the developers will easily Update these records pain free.
if (! in_array($id, $current)) { if (! in_array($id, $current)) {
$this->attach($id, $attributes, $touch); $this->attach($id, $attributes, $touch);
$changes['attached'][] = $this->castKey($id); $changes['attached'][] = $this->castKey($id);
} }
// Now we'll try to update an existing pivot record with the attributes that were // Now we'll try to Update an existing pivot record with the attributes that were
// given to the method. If the model is actually updated we will add it to the // given to the method. If the model is actually updated we will add it to the
// list of updated pivot records so we return them back out to the consumer. // list of updated pivot records so we return them back out to the consumer.
elseif (count($attributes) > 0 && elseif (count($attributes) > 0 &&
...@@ -293,7 +293,7 @@ trait InteractsWithPivotTable ...@@ -293,7 +293,7 @@ trait InteractsWithPivotTable
$record[$this->foreignPivotKey] = $this->parent->{$this->parentKey}; $record[$this->foreignPivotKey] = $this->parent->{$this->parentKey};
// If the record needs to have creation and update timestamps, we will make // If the record needs to have creation and Update timestamps, we will make
// them by calling the parent model's "freshTimestamp" method which will // them by calling the parent model's "freshTimestamp" method which will
// provide us with a fresh timestamp in this model's preferred format. // provide us with a fresh timestamp in this model's preferred format.
if ($timed) { if ($timed) {
...@@ -308,7 +308,7 @@ trait InteractsWithPivotTable ...@@ -308,7 +308,7 @@ trait InteractsWithPivotTable
} }
/** /**
* Set the creation and update timestamps on an attach record. * Set the creation and Update timestamps on an attach record.
* *
* @param array $record * @param array $record
* @param bool $exists * @param bool $exists
......
...@@ -231,7 +231,7 @@ class HasManyThrough extends Relation ...@@ -231,7 +231,7 @@ class HasManyThrough extends Relation
} }
/** /**
* Create or update a related record matching the attributes, and fill it with values. * Create or Update a related record matching the attributes, and fill it with values.
* *
* @param array $attributes * @param array $attributes
* @param array $values * @param array $values
......
...@@ -222,7 +222,7 @@ abstract class HasOneOrMany extends Relation ...@@ -222,7 +222,7 @@ abstract class HasOneOrMany extends Relation
} }
/** /**
* Create or update a related record matching the attributes, and fill it with values. * Create or Update a related record matching the attributes, and fill it with values.
* *
* @param array $attributes * @param array $attributes
* @param array $values * @param array $values
...@@ -309,7 +309,7 @@ abstract class HasOneOrMany extends Relation ...@@ -309,7 +309,7 @@ abstract class HasOneOrMany extends Relation
} }
/** /**
* Perform an update on all the related models. * Perform an Update on all the related models.
* *
* @param array $attributes * @param array $attributes
* @return int * @return int
......
...@@ -26,7 +26,7 @@ class MorphPivot extends Pivot ...@@ -26,7 +26,7 @@ class MorphPivot extends Pivot
protected $morphClass; protected $morphClass;
/** /**
* Set the keys for a save update query. * Set the keys for a save Update query.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
......
...@@ -90,7 +90,7 @@ class Pivot extends Model ...@@ -90,7 +90,7 @@ class Pivot extends Model
} }
/** /**
* Set the keys for a save update query. * Set the keys for a save Update query.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
......
...@@ -167,7 +167,7 @@ abstract class Relation ...@@ -167,7 +167,7 @@ abstract class Relation
} }
/** /**
* Run a raw update against the base query. * Run a raw Update against the base query.
* *
* @param array $attributes * @param array $attributes
* @return int * @return int
......
...@@ -97,7 +97,7 @@ class MigrationCreator ...@@ -97,7 +97,7 @@ class MigrationCreator
// We also have stubs for creating new tables and modifying existing tables // We also have stubs for creating new tables and modifying existing tables
// to save the developer some typing when they are creating a new tables // to save the developer some typing when they are creating a new tables
// or modifying existing tables. We'll grab the appropriate stub here. // or modifying existing tables. We'll grab the appropriate stub here.
$stub = $create ? 'create.stub' : 'update.stub'; $stub = $create ? 'create.stub' : 'Update.stub';
return $this->files->get($this->stubPath()."/{$stub}"); return $this->files->get($this->stubPath()."/{$stub}");
} }
...@@ -116,7 +116,7 @@ class MigrationCreator ...@@ -116,7 +116,7 @@ class MigrationCreator
// Here we will replace the table place-holders with the table specified by // Here we will replace the table place-holders with the table specified by
// the developer, which is useful for quickly creating a tables creation // the developer, which is useful for quickly creating a tables creation
// or update migration from the console instead of typing it manually. // or Update migration from the console instead of typing it manually.
if (! is_null($table)) { if (! is_null($table)) {
$stub = str_replace('DummyTable', $table, $stub); $stub = str_replace('DummyTable', $table, $stub);
} }
......
...@@ -2365,7 +2365,7 @@ class Builder ...@@ -2365,7 +2365,7 @@ class Builder
} }
/** /**
* Insert or update a record matching the attributes, and fill it with values. * Insert or Update a record matching the attributes, and fill it with values.
* *
* @param array $attributes * @param array $attributes
* @param array $values * @param array $values
......
...@@ -714,7 +714,7 @@ class Grammar extends BaseGrammar ...@@ -714,7 +714,7 @@ class Grammar extends BaseGrammar
} }
/** /**
* Compile an update statement into SQL. * Compile an Update statement into SQL.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @param array $values * @param array $values
...@@ -724,7 +724,7 @@ class Grammar extends BaseGrammar ...@@ -724,7 +724,7 @@ class Grammar extends BaseGrammar
{ {
$table = $this->wrapTable($query->from); $table = $this->wrapTable($query->from);
// Each one of the columns in the update statements needs to be wrapped in the // Each one of the columns in the Update statements needs to be wrapped in the
// keyword identifiers, also a place-holder needs to be created for each of // keyword identifiers, also a place-holder needs to be created for each of
// the values in the list of bindings so we can make the sets statements. // the values in the list of bindings so we can make the sets statements.
$columns = collect($values)->map(function ($value, $key) { $columns = collect($values)->map(function ($value, $key) {
...@@ -732,7 +732,7 @@ class Grammar extends BaseGrammar ...@@ -732,7 +732,7 @@ class Grammar extends BaseGrammar
})->implode(', '); })->implode(', ');
// If the query has any "join" clauses, we will setup the joins on the builder // If the query has any "join" clauses, we will setup the joins on the builder
// and compile them so we can attach them to this update, as update queries // and compile them so we can attach them to this Update, as Update queries
// can get join statements to attach to other tables when they're needed. // can get join statements to attach to other tables when they're needed.
$joins = ''; $joins = '';
...@@ -740,16 +740,16 @@ class Grammar extends BaseGrammar ...@@ -740,16 +740,16 @@ class Grammar extends BaseGrammar
$joins = ' '.$this->compileJoins($query, $query->joins); $joins = ' '.$this->compileJoins($query, $query->joins);
} }
// Of course, update queries may also be constrained by where clauses so we'll // Of course, Update queries may also be constrained by where clauses so we'll
// need to compile the where clauses and attach it to the query so only the // need to compile the where clauses and attach it to the query so only the
// intended records are updated by the SQL statements we generate to run. // intended records are updated by the SQL statements we generate to run.
$wheres = $this->compileWheres($query); $wheres = $this->compileWheres($query);
return trim("update {$table}{$joins} set $columns $wheres"); return trim("Update {$table}{$joins} set $columns $wheres");
} }
/** /**
* Prepare the bindings for an update statement. * Prepare the bindings for an Update statement.
* *
* @param array $bindings * @param array $bindings
* @param array $values * @param array $values
......
...@@ -86,14 +86,14 @@ class MySqlGrammar extends Grammar ...@@ -86,14 +86,14 @@ class MySqlGrammar extends Grammar
protected function compileLock(Builder $query, $value) protected function compileLock(Builder $query, $value)
{ {
if (! is_string($value)) { if (! is_string($value)) {
return $value ? 'for update' : 'lock in share mode'; return $value ? 'for Update' : 'lock in share mode';
} }
return $value; return $value;
} }
/** /**
* Compile an update statement into SQL. * Compile an Update statement into SQL.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @param array $values * @param array $values
...@@ -103,13 +103,13 @@ class MySqlGrammar extends Grammar ...@@ -103,13 +103,13 @@ class MySqlGrammar extends Grammar
{ {
$table = $this->wrapTable($query->from); $table = $this->wrapTable($query->from);
// Each one of the columns in the update statements needs to be wrapped in the // Each one of the columns in the Update statements needs to be wrapped in the
// keyword identifiers, also a place-holder needs to be created for each of // keyword identifiers, also a place-holder needs to be created for each of
// the values in the list of bindings so we can make the sets statements. // the values in the list of bindings so we can make the sets statements.
$columns = $this->compileUpdateColumns($values); $columns = $this->compileUpdateColumns($values);
// If the query has any "join" clauses, we will setup the joins on the builder // If the query has any "join" clauses, we will setup the joins on the builder
// and compile them so we can attach them to this update, as update queries // and compile them so we can attach them to this Update, as Update queries
// can get join statements to attach to other tables when they're needed. // can get join statements to attach to other tables when they're needed.
$joins = ''; $joins = '';
...@@ -117,23 +117,23 @@ class MySqlGrammar extends Grammar ...@@ -117,23 +117,23 @@ class MySqlGrammar extends Grammar
$joins = ' '.$this->compileJoins($query, $query->joins); $joins = ' '.$this->compileJoins($query, $query->joins);
} }
// Of course, update queries may also be constrained by where clauses so we'll // Of course, Update queries may also be constrained by where clauses so we'll
// need to compile the where clauses and attach it to the query so only the // need to compile the where clauses and attach it to the query so only the
// intended records are updated by the SQL statements we generate to run. // intended records are updated by the SQL statements we generate to run.
$where = $this->compileWheres($query); $where = $this->compileWheres($query);
$sql = rtrim("update {$table}{$joins} set $columns $where"); $sql = rtrim("Update {$table}{$joins} set $columns $where");
// If the query has an order by clause we will compile it since MySQL supports // If the query has an order by clause we will compile it since MySQL supports
// order bys on update statements. We'll compile them using the typical way // order bys on Update statements. We'll compile them using the typical way
// of compiling order bys. Then they will be appended to the SQL queries. // of compiling order bys. Then they will be appended to the SQL queries.
if (! empty($query->orders)) { if (! empty($query->orders)) {
$sql .= ' '.$this->compileOrders($query, $query->orders); $sql .= ' '.$this->compileOrders($query, $query->orders);
} }
// Updates on MySQL also supports "limits", which allow you to easily update a // Updates on MySQL also supports "limits", which allow you to easily Update a
// single record very easily. This is not supported by all database engines // single record very easily. This is not supported by all database engines
// so we have customized this update compiler here in order to add it in. // so we have customized this Update compiler here in order to add it in.
if (isset($query->limit)) { if (isset($query->limit)) {
$sql .= ' '.$this->compileLimit($query, $query->limit); $sql .= ' '.$this->compileLimit($query, $query->limit);
} }
...@@ -142,7 +142,7 @@ class MySqlGrammar extends Grammar ...@@ -142,7 +142,7 @@ class MySqlGrammar extends Grammar
} }
/** /**
* Compile all of the columns for an update statement. * Compile all of the columns for an Update statement.
* *
* @param array $values * @param array $values
* @return string * @return string
...@@ -177,7 +177,7 @@ class MySqlGrammar extends Grammar ...@@ -177,7 +177,7 @@ class MySqlGrammar extends Grammar
} }
/** /**
* Prepare the bindings for an update statement. * Prepare the bindings for an Update statement.
* *
* Booleans, integers, and doubles are inserted into JSON updates as raw values. * Booleans, integers, and doubles are inserted into JSON updates as raw values.
* *
......
...@@ -74,7 +74,7 @@ class PostgresGrammar extends Grammar ...@@ -74,7 +74,7 @@ class PostgresGrammar extends Grammar
protected function compileLock(Builder $query, $value) protected function compileLock(Builder $query, $value)
{ {
if (! is_string($value)) { if (! is_string($value)) {
return $value ? 'for update' : 'for share'; return $value ? 'for Update' : 'for share';
} }
return $value; return $value;
...@@ -110,7 +110,7 @@ class PostgresGrammar extends Grammar ...@@ -110,7 +110,7 @@ class PostgresGrammar extends Grammar
} }
/** /**
* Compile an update statement into SQL. * Compile an Update statement into SQL.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @param array $values * @param array $values
...@@ -120,7 +120,7 @@ class PostgresGrammar extends Grammar ...@@ -120,7 +120,7 @@ class PostgresGrammar extends Grammar
{ {
$table = $this->wrapTable($query->from); $table = $this->wrapTable($query->from);
// Each one of the columns in the update statements needs to be wrapped in the // Each one of the columns in the Update statements needs to be wrapped in the
// keyword identifiers, also a place-holder needs to be created for each of // keyword identifiers, also a place-holder needs to be created for each of
// the values in the list of bindings so we can make the sets statements. // the values in the list of bindings so we can make the sets statements.
$columns = $this->compileUpdateColumns($values); $columns = $this->compileUpdateColumns($values);
...@@ -129,27 +129,27 @@ class PostgresGrammar extends Grammar ...@@ -129,27 +129,27 @@ class PostgresGrammar extends Grammar
$where = $this->compileUpdateWheres($query); $where = $this->compileUpdateWheres($query);
return trim("update {$table} set {$columns}{$from} {$where}"); return trim("Update {$table} set {$columns}{$from} {$where}");
} }
/** /**
* Compile the columns for the update statement. * Compile the columns for the Update statement.
* *
* @param array $values * @param array $values
* @return string * @return string
*/ */
protected function compileUpdateColumns($values) protected function compileUpdateColumns($values)
{ {
// When gathering the columns for an update statement, we'll wrap each of the // When gathering the columns for an Update statement, we'll wrap each of the
// columns and convert it to a parameter value. Then we will concatenate a // columns and convert it to a parameter value. Then we will concatenate a
// list of the columns that can be added into this update query clauses. // list of the columns that can be added into this Update query clauses.
return collect($values)->map(function ($value, $key) { return collect($values)->map(function ($value, $key) {
return $this->wrap($key).' = '.$this->parameter($value); return $this->wrap($key).' = '.$this->parameter($value);
})->implode(', '); })->implode(', ');
} }
/** /**
* Compile the "from" clause for an update with a join. * Compile the "from" clause for an Update with a join.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @return string|null * @return string|null
...@@ -199,7 +199,7 @@ class PostgresGrammar extends Grammar ...@@ -199,7 +199,7 @@ class PostgresGrammar extends Grammar
} }
/** /**
* Compile the "join" clause where clauses for an update. * Compile the "join" clause where clauses for an Update.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @return string * @return string
...@@ -223,7 +223,7 @@ class PostgresGrammar extends Grammar ...@@ -223,7 +223,7 @@ class PostgresGrammar extends Grammar
} }
/** /**
* Prepare the bindings for an update statement. * Prepare the bindings for an Update statement.
* *
* @param array $bindings * @param array $bindings
* @param array $values * @param array $values
......
...@@ -187,7 +187,7 @@ class SQLiteGrammar extends Grammar ...@@ -187,7 +187,7 @@ class SQLiteGrammar extends Grammar
} }
/** /**
* Compile an update statement into SQL. * Compile an Update statement into SQL.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @param array $values * @param array $values
...@@ -204,14 +204,14 @@ class SQLiteGrammar extends Grammar ...@@ -204,14 +204,14 @@ class SQLiteGrammar extends Grammar
if (isset($query->joins) || isset($query->limit)) { if (isset($query->joins) || isset($query->limit)) {
$selectSql = parent::compileSelect($query->select("{$query->from}.rowid")); $selectSql = parent::compileSelect($query->select("{$query->from}.rowid"));
return "update {$table} set $columns where {$this->wrap('rowid')} in ({$selectSql})"; return "Update {$table} set $columns where {$this->wrap('rowid')} in ({$selectSql})";
} }
return trim("update {$table} set {$columns} {$this->compileWheres($query)}"); return trim("Update {$table} set {$columns} {$this->compileWheres($query)}");
} }
/** /**
* Prepare the bindings for an update statement. * Prepare the bindings for an Update statement.
* *
* @param array $bindings * @param array $bindings
* @param array $values * @param array $values
......
...@@ -287,7 +287,7 @@ class SqlServerGrammar extends Grammar ...@@ -287,7 +287,7 @@ class SqlServerGrammar extends Grammar
} }
/** /**
* Compile an update statement into SQL. * Compile an Update statement into SQL.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @param array $values * @param array $values
...@@ -297,7 +297,7 @@ class SqlServerGrammar extends Grammar ...@@ -297,7 +297,7 @@ class SqlServerGrammar extends Grammar
{ {
list($table, $alias) = $this->parseUpdateTable($query->from); list($table, $alias) = $this->parseUpdateTable($query->from);
// Each one of the columns in the update statements needs to be wrapped in the // Each one of the columns in the Update statements needs to be wrapped in the
// keyword identifiers, also a place-holder needs to be created for each of // keyword identifiers, also a place-holder needs to be created for each of
// the values in the list of bindings so we can make the sets statements. // the values in the list of bindings so we can make the sets statements.
$columns = collect($values)->map(function ($value, $key) { $columns = collect($values)->map(function ($value, $key) {
...@@ -305,7 +305,7 @@ class SqlServerGrammar extends Grammar ...@@ -305,7 +305,7 @@ class SqlServerGrammar extends Grammar
})->implode(', '); })->implode(', ');
// If the query has any "join" clauses, we will setup the joins on the builder // If the query has any "join" clauses, we will setup the joins on the builder
// and compile them so we can attach them to this update, as update queries // and compile them so we can attach them to this Update, as Update queries
// can get join statements to attach to other tables when they're needed. // can get join statements to attach to other tables when they're needed.
$joins = ''; $joins = '';
...@@ -313,16 +313,16 @@ class SqlServerGrammar extends Grammar ...@@ -313,16 +313,16 @@ class SqlServerGrammar extends Grammar
$joins = ' '.$this->compileJoins($query, $query->joins); $joins = ' '.$this->compileJoins($query, $query->joins);
} }
// Of course, update queries may also be constrained by where clauses so we'll // Of course, Update queries may also be constrained by where clauses so we'll
// need to compile the where clauses and attach it to the query so only the // need to compile the where clauses and attach it to the query so only the
// intended records are updated by the SQL statements we generate to run. // intended records are updated by the SQL statements we generate to run.
$where = $this->compileWheres($query); $where = $this->compileWheres($query);
if (! empty($joins)) { if (! empty($joins)) {
return trim("update {$alias} set {$columns} from {$table}{$joins} {$where}"); return trim("Update {$alias} set {$columns} from {$table}{$joins} {$where}");
} }
return trim("update {$table}{$joins} set $columns $where"); return trim("Update {$table}{$joins} set $columns $where");
} }
/** /**
...@@ -343,7 +343,7 @@ class SqlServerGrammar extends Grammar ...@@ -343,7 +343,7 @@ class SqlServerGrammar extends Grammar
} }
/** /**
* Prepare the bindings for an update statement. * Prepare the bindings for an Update statement.
* *
* @param array $bindings * @param array $bindings
* @param array $values * @param array $values
......
...@@ -931,7 +931,7 @@ class Blueprint ...@@ -931,7 +931,7 @@ class Blueprint
} }
/** /**
* Add nullable creation and update timestamps to the table. * Add nullable creation and Update timestamps to the table.
* *
* @param int $precision * @param int $precision
* @return void * @return void
...@@ -944,7 +944,7 @@ class Blueprint ...@@ -944,7 +944,7 @@ class Blueprint
} }
/** /**
* Add nullable creation and update timestamps to the table. * Add nullable creation and Update timestamps to the table.
* *
* Alias for self::timestamps(). * Alias for self::timestamps().
* *
...@@ -957,7 +957,7 @@ class Blueprint ...@@ -957,7 +957,7 @@ class Blueprint
} }
/** /**
* Add creation and update timestampTz columns to the table. * Add creation and Update timestampTz columns to the table.
* *
* @param int $precision * @param int $precision
* @return void * @return void
......
...@@ -81,14 +81,14 @@ abstract class Grammar extends BaseGrammar ...@@ -81,14 +81,14 @@ abstract class Grammar extends BaseGrammar
); );
// Once we have the basic foreign key creation statement constructed we can // Once we have the basic foreign key creation statement constructed we can
// build out the syntax for what should happen on an update or delete of // build out the syntax for what should happen on an Update or delete of
// the affected columns, which will get something like "cascade", etc. // the affected columns, which will get something like "cascade", etc.
if (! is_null($command->onDelete)) { if (! is_null($command->onDelete)) {
$sql .= " on delete {$command->onDelete}"; $sql .= " on delete {$command->onDelete}";
} }
if (! is_null($command->onUpdate)) { if (! is_null($command->onUpdate)) {
$sql .= " on update {$command->onUpdate}"; $sql .= " on Update {$command->onUpdate}";
} }
return $sql; return $sql;
......
...@@ -83,11 +83,11 @@ class SQLiteGrammar extends Grammar ...@@ -83,11 +83,11 @@ class SQLiteGrammar extends Grammar
$sql .= " on delete {$foreign->onDelete}"; $sql .= " on delete {$foreign->onDelete}";
} }
// If this foreign key specifies the action to be taken on update we will add // If this foreign key specifies the action to be taken on Update we will add
// that to the statement here. We'll append it to this SQL and then return // that to the statement here. We'll append it to this SQL and then return
// the SQL so we can keep adding any other foreign constraints onto this. // the SQL so we can keep adding any other foreign constraints onto this.
if (! is_null($foreign->onUpdate)) { if (! is_null($foreign->onUpdate)) {
$sql .= " on update {$foreign->onUpdate}"; $sql .= " on Update {$foreign->onUpdate}";
} }
return $sql; return $sql;
......
...@@ -11,7 +11,7 @@ namespace Illuminate\Support\Facades; ...@@ -11,7 +11,7 @@ namespace Illuminate\Support\Facades;
* @method static mixed selectOne(string $query, array $bindings = []) * @method static mixed selectOne(string $query, array $bindings = [])
* @method static array select(string $query, array $bindings = []) * @method static array select(string $query, array $bindings = [])
* @method static bool insert(string $query, array $bindings = []) * @method static bool insert(string $query, array $bindings = [])
* @method static int update(string $query, array $bindings = []) * @method static int Update(string $query, array $bindings = [])
* @method static int delete(string $query, array $bindings = []) * @method static int delete(string $query, array $bindings = [])
* @method static bool statement(string $query, array $bindings = []) * @method static bool statement(string $query, array $bindings = [])
* @method static int affectingStatement(string $query, array $bindings = []) * @method static int affectingStatement(string $query, array $bindings = [])
......
...@@ -112,7 +112,7 @@ class RotatingFileHandler extends StreamHandler ...@@ -112,7 +112,7 @@ class RotatingFileHandler extends StreamHandler
*/ */
protected function rotate() protected function rotate()
{ {
// update filename // Update filename
$this->url = $this->getTimedFilename(); $this->url = $this->getTimedFilename();
$this->nextRotation = new \DateTime('tomorrow'); $this->nextRotation = new \DateTime('tomorrow');
......
...@@ -28,7 +28,7 @@ class AmqpHandlerTest extends TestCase ...@@ -28,7 +28,7 @@ class AmqpHandlerTest extends TestCase
} }
if (!class_exists('AMQPChannel')) { if (!class_exists('AMQPChannel')) {
$this->markTestSkipped("Please update AMQP to version >= 1.0"); $this->markTestSkipped("Please Update AMQP to version >= 1.0");
} }
$messages = array(); $messages = array();
......
...@@ -14,13 +14,13 @@ env: ...@@ -14,13 +14,13 @@ env:
sudo: false sudo: false
before_install: before_install:
- sudo apt-get update && sudo apt-get --reinstall install -qq language-pack-fr - sudo apt-get Update && sudo apt-get --reinstall install -qq language-pack-fr
- if [[ $coverage = 'false' ]]; then phpenv config-rm xdebug.ini; fi - if [[ $coverage = 'false' ]]; then phpenv config-rm xdebug.ini; fi
install: install:
- if [[ $phpstan = 'true' ]]; then travis_retry composer require --dev phpstan/phpstan; fi - if [[ $phpstan = 'true' ]]; then travis_retry composer require --dev phpstan/phpstan; fi
- if [[ $setup = 'basic' ]]; then travis_retry composer update --prefer-dist --no-interaction --no-suggest; fi - if [[ $setup = 'basic' ]]; then travis_retry composer Update --prefer-dist --no-interaction --no-suggest; fi
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --no-suggest --prefer-stable; fi - if [[ $setup = 'stable' ]]; then travis_retry composer Update --prefer-dist --no-interaction --no-suggest --prefer-stable; fi
- | - |
if [[ $setup = 'lowest' ]]; then if [[ $setup = 'lowest' ]]; then
composer require sebastian/comparator:"~1.2.4" --no-update --dev composer require sebastian/comparator:"~1.2.4" --no-update --dev
......
...@@ -46,7 +46,7 @@ foreach ($tags as $tag) { ...@@ -46,7 +46,7 @@ foreach ($tags as $tag) {
shell_exec("git branch -d $branch"); shell_exec("git branch -d $branch");
shell_exec("git checkout tags/$tag -b $branch"); shell_exec("git checkout tags/$tag -b $branch");
shell_exec('composer config platform.php 5.3.9'); shell_exec('composer config platform.php 5.3.9');
shell_exec('composer update --no-interaction --no-dev --optimize-autoloader'); shell_exec('composer Update --no-interaction --no-dev --optimize-autoloader');
$zip = new ZipArchive(); $zip = new ZipArchive();
$zip->open($archive, ZipArchive::CREATE | ZipArchive::OVERWRITE); $zip->open($archive, ZipArchive::CREATE | ZipArchive::OVERWRITE);
...@@ -81,7 +81,7 @@ foreach ($tags as $tag) { ...@@ -81,7 +81,7 @@ foreach ($tags as $tag) {
shell_exec("git checkout $currentBranch"); shell_exec("git checkout $currentBranch");
shell_exec("git branch -d $branch"); shell_exec("git branch -d $branch");
shell_exec('git stash pop'); shell_exec('git stash pop');
shell_exec('composer update --no-interaction'); shell_exec('composer Update --no-interaction');
} }
exit(0); exit(0);
...@@ -98,7 +98,7 @@ interface RequestInterface extends MessageInterface ...@@ -98,7 +98,7 @@ interface RequestInterface extends MessageInterface
/** /**
* Returns an instance with the provided URI. * Returns an instance with the provided URI.
* *
* This method MUST update the Host header of the returned request by * This method MUST Update the Host header of the returned request by
* default if the URI contains a host component. If the URI does not * default if the URI contains a host component. If the URI does not
* contain a host component, any pre-existing Host header MUST be carried * contain a host component, any pre-existing Host header MUST be carried
* over to the returned request. * over to the returned request.
...@@ -108,12 +108,12 @@ interface RequestInterface extends MessageInterface ...@@ -108,12 +108,12 @@ interface RequestInterface extends MessageInterface
* `true`, this method interacts with the Host header in the following ways: * `true`, this method interacts with the Host header in the following ways:
* *
* - If the Host header is missing or empty, and the new URI contains * - If the Host header is missing or empty, and the new URI contains
* a host component, this method MUST update the Host header in the returned * a host component, this method MUST Update the Host header in the returned
* request. * request.
* - If the Host header is missing or empty, and the new URI does not contain a * - If the Host header is missing or empty, and the new URI does not contain a
* host component, this method MUST NOT update the Host header in the returned * host component, this method MUST NOT Update the Host header in the returned
* request. * request.
* - If a Host header is present and non-empty, this method MUST NOT update * - If a Host header is present and non-empty, this method MUST NOT Update
* the Host header in the returned request. * the Host header in the returned request.
* *
* This method MUST be implemented in such a way as to retain the * This method MUST be implemented in such a way as to retain the
......
...@@ -72,7 +72,7 @@ interface ServerRequestInterface extends RequestInterface ...@@ -72,7 +72,7 @@ interface ServerRequestInterface extends RequestInterface
* be compatible with the structure of $_COOKIE. Typically, this data will * be compatible with the structure of $_COOKIE. Typically, this data will
* be injected at instantiation. * be injected at instantiation.
* *
* This method MUST NOT update the related Cookie header of the request * This method MUST NOT Update the related Cookie header of the request
* instance, nor related values in the server params. * instance, nor related values in the server params.
* *
* This method MUST be implemented in such a way as to retain the * This method MUST be implemented in such a way as to retain the
......
{
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": {
"name": "cdzpay",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/configmaps/cdzpay",
"uid": "56609fea-99f6-11e8-a154-02fba74a71a4",
"resourceVersion": "57326041",
"creationTimestamp": "2018-08-07T03:59:52Z"
},
"data": {
"API_CONDITIONAL_REQUEST": "false",
"API_DEBUG": "true",
"API_DOMAIN": "cdzpay.staging.senthink.com",
"API_NAME": "cdz",
"API_PREFIX": "api",
"API_STANDARDS_TREE": "x",
"API_STRICT": "false",
"API_SUBTYPE": "cdz",
"API_VERSION": "v1",
"APP_DEBUG": "true",
"APP_ENV": "local",
"APP_KEY": "base64:eT7rjn+lf0GHA73E06rxhri1iVDYCRN70RhWxXEo7IM=",
"APP_LOCALE": "zh-CN",
"APP_LOG": "daily",
"APP_TIMEZONE": "PRC",
"CACHE_DRIVER": "file",
"DB_CONNECTION": "mysql",
"DB_DATABASE": "cdzpay",
"DB_HOST": "db.staging.senthink.com",
"DB_PASSWORD": "RRryCfWBXq2Whdq",
"DB_PORT": "3306",
"DB_USERNAME": "senthink",
"GATEWAY_REGISTER": "cdzregister.default.svc.cluster.local:1239",
"JWT_SECRET": "hISaT0VHD8tPvkr9siK2SY21FYtlyH2a",
"LOG_CHANNEL": "daily",
"MANAGE_HOST": "https://cdzback2.staging.senthink.com",
"PRE_DB_DATABASE": "stagingrevealcdz",
"PRE_DB_HOST": "db.staging.senthink.com",
"PRE_DB_PASSWORD": "RRryCfWBXq2Whdq",
"PRE_DB_PORT": "3306",
"PRE_DB_USERNAME": "senthink",
"QUEUE_DRIVER": "sync",
"RABBIT_HOST": "rabbitmq.default.svc.cluster.local",
"RABBIT_LOGIN": "rabbitmq",
"RABBIT_PASSWORD": "senthink123!",
"RABBIT_PORT": "5672",
"RABBIT_VHOST": "cdz_gateway",
"REDIS_HOST": "redis.default.svc.cluster.local",
"REDIS_PORT": "6379",
"WX_APP_ID": "wx5a234043195ec484",
"WX_APP_KEY": "shengpeng2017shengpeng2017shengp",
"WX_APP_SECRET": "74af342df5f80ed48e32deffe893de56",
"WX_MCH_ID": "1426979702",
"WX_TOKEN": "hahaha"
}
}
\ No newline at end of file
<?php
namespace Lib;
class Crc
{
const CRC_TABLE = [
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
];
/**
* @param $data
* @return int
*/
public static function crc($data)
{
$crc = 0xffffffff;
$size = strlen($data);
for ($i = 0; $i < $size; $i += 2) {
$numHex = substr($data, $i, 2);
$number = hexdec($numHex);
$tmp = ($crc ^ $number) & 0xff;
$crcRightMove = (hexdec(sprintf("%08x", $crc >> 8)));
$crc = ($crcRightMove) ^ (self::CRC_TABLE[$tmp]);
}
return $crc ^ 0xffffffff;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/11/2
* Time: 下午8:48
*/
namespace Lib;
use GuzzleHttp\Client;
use Lib\iot\AccessToken;
use Illuminate\Support\Facades\Log;
class IotGateway
{
public static $appId = '';
public static $deviceId = '';
public static $command = '';
public static $expireTime = 0;
public static $maxRetransmit = 1;
private static function init()
{
static::$appId = env('IOT_APP_ID');
}
public static function bindUid(string $clientId, string $uid)
{
}
public static function sendToClient(string $clientId, string $message)
{
Log::debug('send message' . $message);
$client = new Client();
$request = [
'verify' => false,
'cert' => [
config('iot.cert_path'),
'IoM@1234',
]
];
$request['headers'] = [
'app_key' => env('IOT_APP_ID'),
'Authorization' => 'Bearer ' . AccessToken::getAccessTokenCache(),
'Content-Type' => 'application/json',
];
// 'appId' => env('IOT_APP_ID'),
$request['json'] = [
'deviceId' => $clientId,
'command' =>
['serviceId' => 'Transmission',
'method' => 'Cmd_Res',
'paras' => ['downData' => strtoupper($message)],
],
'expireTime' => static::$expireTime,
'maxRetransmit' => static::$maxRetransmit
];
Log::debug('response = ' . $message);
$response = $client->request('POST', config('iot.host') . 'iocm/app/cmd/v1.4.0/deviceCommands', $request);
if ($response->getStatusCode() === 201) {
return true;
}
return false;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 下午2:27
*/
namespace Lib;
class ToHex
{
public static function toHex(int $data, int $length): string
{
return sprintf('%0' . $length * 2 . 'x', $data);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/29
* Time: 上午10:25
*/
namespace Lib;
class Tool
{
public static function padding($data, $length)
{
$length *= 2;
return sprintf('%0' . $length . 'x', $data);
}
}
\ No newline at end of file
...@@ -20,6 +20,11 @@ class BalanceOrder ...@@ -20,6 +20,11 @@ class BalanceOrder
/** /**
* @var int * @var int
*/ */
private $typeId = 1;
/**
* @var int
*/
private $userId; private $userId;
...@@ -90,6 +95,7 @@ class BalanceOrder ...@@ -90,6 +95,7 @@ class BalanceOrder
* @var int * @var int
*/ */
private $discount; private $discount;
/** /**
* @return Station * @return Station
*/ */
...@@ -107,8 +113,6 @@ class BalanceOrder ...@@ -107,8 +113,6 @@ class BalanceOrder
} }
/** /**
* @return int * @return int
*/ */
...@@ -242,9 +246,8 @@ class BalanceOrder ...@@ -242,9 +246,8 @@ class BalanceOrder
*/ */
public function getOrderId(): int public function getOrderId(): int
{ {
if(blank($this->orderId)) if (blank($this->orderId)) {
{ $result = DB::table('wx_charger_orders')->where('out_trade_no', $this->outTradeNo)->first(['id']);
$result = DB::table('wx_charger_orders')->where('out_trade_no',$this->outTradeNo)->first(['id']);
$this->orderId = $result->id; $this->orderId = $result->id;
...@@ -324,10 +327,21 @@ class BalanceOrder ...@@ -324,10 +327,21 @@ class BalanceOrder
$this->discount = $discount; $this->discount = $discount;
} }
/**
* @return int
*/
public function getTypeId(): int
{
return $this->typeId;
}
/**
* @param int $typeId
*/
public function setTypeId(int $typeId): void
{
$this->typeId = $typeId;
}
} }
\ No newline at end of file
...@@ -9,10 +9,12 @@ ...@@ -9,10 +9,12 @@
namespace Lib\balance\charger\handle; namespace Lib\balance\charger\handle;
use App\Model\GatewayModel;
use Lib\balance\BalanceOrder; use Lib\balance\BalanceOrder;
use Lib\balance\charger\handle\fail\StopChargerHandle; use Lib\balance\charger\handle\fail\StopChargerHandle;
use Lib\balance\charger\HandleClient; use Lib\balance\charger\HandleClient;
use Lib\gateway\Gateway; use Lib\gateway\Gateway;
use Lib\IotGateway;
use Lib\order_exception\OrderState; use Lib\order_exception\OrderState;
use Lib\send\command\BalanceChargerCommand; use Lib\send\command\BalanceChargerCommand;
use Lib\send\command\ChargerCommand; use Lib\send\command\ChargerCommand;
...@@ -48,13 +50,41 @@ class ChargerHandle extends Handle ...@@ -48,13 +50,41 @@ class ChargerHandle extends Handle
$balanceOrder->setPortLogic($portLogicNum); $balanceOrder->setPortLogic($portLogicNum);
$gatewayModel = GatewayModel::find($gatewayId);
$gatewayType = $gatewayModel->type_id;
$nbDeviceId = $gatewayModel->nb_device_id;
$sendResult = false;
if ($gatewayType === 5) {
$chargerCommand = new \Lib\iot\command\ChargerCommand();
$chargerCommand->setOrderId($balanceOrder->getOrderId());
$chargerCommand->setTime($balanceOrder->getTime());
$chargerCommand->setType(1);
$chargerCommand->setServiceId(time() . rand(10000, 99999));
$chargerCommand->setPortLogic(0);
$chargerCommand->organizeMessage();
$send = $chargerCommand;
if (IotGateway::sendToClient($nbDeviceId, $chargerCommand->getMessage())) {
Log::debug('send nb charger command success');
$sendResult = true;
} else {
Log::error('send nb charger fail');
};
} else {
$balanceChargerCommand = new BalanceChargerCommand($balanceOrder); $balanceChargerCommand = new BalanceChargerCommand($balanceOrder);
$send = new Send($balanceChargerCommand); $send = new Send($balanceChargerCommand);
$sendResult = $send->send();
}
if($send->send() === true) if ($sendResult) {
{
DB::table('gateway_log')->insert([ DB::table('gateway_log')->insert([
'gateway_id' => $balanceOrder->getGatewayId(), 'gateway_id' => $balanceOrder->getGatewayId(),
...@@ -62,7 +92,7 @@ class ChargerHandle extends Handle ...@@ -62,7 +92,7 @@ class ChargerHandle extends Handle
'port_id' => $balanceOrder->getPort()->getPortId(), 'port_id' => $balanceOrder->getPort()->getPortId(),
'created_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'),
'command' => '04', 'command' => '04',
'request'=> $send->getMessage(), 'request' => $send->getMessage(),
'type' => 1, 'type' => 1,
'station_id' => $balanceOrder->getStationId(), 'station_id' => $balanceOrder->getStationId(),
]); ]);
...@@ -79,30 +109,26 @@ class ChargerHandle extends Handle ...@@ -79,30 +109,26 @@ class ChargerHandle extends Handle
$orderState = new OrderState($balanceOrder->getOrderId()); $orderState = new OrderState($balanceOrder->getOrderId());
$orderState->setState(-1); $orderState->setState(-1);
}catch (\Exception $exception) } catch (\Exception $exception) {
{
Log::error($exception->getMessage()); Log::error($exception->getMessage());
} }
}else{ } else {
$handleClient->setIsSuccess(false); $handleClient->setIsSuccess(false);
$handleClient->setFailMessage('端口打开失败'); $handleClient->setFailMessage('端口打开失败');
return ; return;
} }
if($this->successHandle instanceof Handle) if ($this->successHandle instanceof Handle) {
{ $this->successHandle->handle($balanceOrder, $handleClient);
$this->successHandle->handle($balanceOrder,$handleClient);
} }
} }
......
...@@ -14,7 +14,6 @@ use Log; ...@@ -14,7 +14,6 @@ use Log;
class Order class Order
{ {
/** /**
* @var int * @var int
*/ */
...@@ -145,7 +144,6 @@ class Order ...@@ -145,7 +144,6 @@ class Order
} }
return $this->orderCache; return $this->orderCache;
} }
...@@ -434,5 +432,4 @@ class Order ...@@ -434,5 +432,4 @@ class Order
} }
} }
\ No newline at end of file
...@@ -45,6 +45,7 @@ class UsingOrderAdaptor ...@@ -45,6 +45,7 @@ class UsingOrderAdaptor
} }
return [ return [
'port_id' => $orderCache['portId'], 'port_id' => $orderCache['portId'],
...@@ -52,7 +53,7 @@ class UsingOrderAdaptor ...@@ -52,7 +53,7 @@ class UsingOrderAdaptor
'state' => $orderCache['stateCode'], 'state' => $orderCache['stateCode'],
'order_id' => $orderCache['id'], 'order_id' => $orderCache['id'],
'charger_time' => $orderCache['purchaseTime'], 'charger_time' => $orderCache['purchaseTime'],
'created_at' => date('Y-m-d H:i:s', $orderCache['createdTime']), 'created_at' => date('Y-m-d H:i:s', isset($orderCache['startTime']) ? $orderCache['startTime'] : $orderCache['createdTime']),
'port_name' => $orderCache['portName'], 'port_name' => $orderCache['portName'],
'order_amount' => number_format($orderCache['payAmount'] / 100, 2), 'order_amount' => number_format($orderCache['payAmount'] / 100, 2),
'start_time' => isset($orderCache['startTime']) ? date('Y-m-d H:i:s', $orderCache['startTime']) : null, 'start_time' => isset($orderCache['startTime']) ? date('Y-m-d H:i:s', $orderCache['startTime']) : null,
......
...@@ -227,4 +227,5 @@ class Port ...@@ -227,4 +227,5 @@ class Port
} }
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/28
* Time: 上午10:47
*/
namespace Lib\iot;
use Lib\redis\RedisSingle;
use Psr\Http\Message\ResponseInterface;
class AccessToken implements Request
{
const ACCESS_CACHE_KEY = 'cdz:iot:access_token';
const REFRESH_ACCESS_CACHE_KEY = 'cdz:iot:refresh_token';
protected $url = 'iocm/app/sec/v1.1.0/login';
protected $method = 'POST';
protected $formData = [];
private $appId = '';
private $appSecret = '';
private $accessToken = '';
private $refreshToken = '';
public function __construct()
{
$this->appId = env('IOT_APP_ID');
$this->appSecret = env('IOT_APP_SECRET');
}
public function getReturnCode(): int
{
return 200;
}
public function isJson(): bool
{
return false;
}
public function parseResponse(ResponseInterface $response)
{
$body = json_decode($response->getBody(), true);
$this->accessToken = $body['accessToken'];
$expiresLn = $body['expiresIn'];
$this->refreshToken = $body['refreshToken'];
$redis = RedisSingle::getRedis();
if ($redis instanceof \Redis) {
$redis->set(self::ACCESS_CACHE_KEY, $this->accessToken, $expiresLn);
$redis->set(self::REFRESH_ACCESS_CACHE_KEY, $this->refreshToken, 25 * 24 * 60);
}
}
public static function getAccessTokenCache()
{
$redis = RedisSingle::getRedis();
// $redis->del(self::ACCESS_CACHE_KEY);
// $redis->del(self::REFRESH_ACCESS_CACHE_KEY);
if ($redis->exists(self::ACCESS_CACHE_KEY) == true) {
return $redis->get(self::ACCESS_CACHE_KEY);
} else if ($redis->exists(self::REFRESH_ACCESS_CACHE_KEY) === true) {
//todo refresh 换取token 并缓存新的token和新的refresh
$refreshToken = new RefreshToken();
$refreshToken->setRefreshToken($redis->get(self::REFRESH_ACCESS_CACHE_KEY));
$iotClient = new IotClient($refreshToken);
if ($iotClient->request() === true) {
$response = $iotClient->getResponse();
$accessToken = $refreshToken->parseResponse($response);
return $accessToken->getAccessToken();
}
} else {
//todo 请求token
$accessToken = new AccessToken();
$iotClient = new IotClient($accessToken);
if ($iotClient->request() === true) {
$accessToken->parseResponse($iotClient->getResponse());
return $accessToken->getAccessToken();
}
}
}
/**
* @return mixed|string
*/
public function getAppId()
{
return $this->appId;
}
/**
* @param mixed|string $appId
*/
public function setAppId($appId): void
{
$this->appId = $appId;
}
/**
* @return mixed|string
*/
public function getAppSecret()
{
return $this->appSecret;
}
/**
* @param mixed|string $appSecret
*/
public function setAppSecret($appSecret): void
{
$this->appSecret = $appSecret;
}
/**
* @return string
*/
public function getAccessToken(): string
{
return $this->accessToken;
}
/**
* @param string $accessToken
*/
public function setAccessToken(string $accessToken): void
{
$this->accessToken = $accessToken;
}
/**
* @return string
*/
public function getRefreshToken(): string
{
return $this->refreshToken;
}
/**
* @param string $refreshToken
*/
public function setRefreshToken(string $refreshToken): void
{
$this->refreshToken = $refreshToken;
}
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url): void
{
$this->url = $url;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @param string $method
*/
public function setMethod(string $method): void
{
$this->method = $method;
}
/**
* @return array
*/
public function getFormData(): array
{
$this->formData = [
'appId' => $this->appId,
'secret' => $this->appSecret,
];
return $this->formData;
}
/**
* @param array $formData
*/
public function setFormData(array $formData): void
{
$this->formData = $formData;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/28
* Time: 上午10:51
*/
namespace Lib\iot;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
class IotClient
{
/**
* @var Request
*/
private $request;
private $headers = [];
/**
* @var ResponseInterface
*/
private $response;
public function __construct(Request $request)
{
$this->request = $request;
}
public function setDefaultHeader()
{
$this->headers = [
'app_key' => env('IOT_APP_ID'),
'Authorization' => 'Bearer ' . AccessToken::getAccessTokenCache(),
];
if ($this->request->isJson() === true) {
$this->headers['Content-Type'] = 'application/json';
}
}
/**
* @param int $returnCode
* @return bool
*/
public function request($returnCode = 200): bool
{
$client = new Client();
$request = [
'verify' => false,
'cert' => [
config('iot.cert_path'),
'IoM@1234',
]
];
if (filled($this->headers) === true) {
$request['headers'] = $this->headers;
}
if ($this->request->isJson() === false) {
$request['form_params'] = $this->request->getFormData();
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
} else {
$request['json'] = $this->request->getFormData();
$this->response = $client->request($this->request->getMethod(), config('iot.host') . $this->request->getUrl(), $request);
}
return $this->response->getStatusCode() === $returnCode;
}
/**
* @return ResponseInterface
*/
public function getResponse(): ResponseInterface
{
return $this->response;
}
/**
* @return Request
*/
public function getRequest(): Request
{
return $this->request;
}
/**
* @param Request $request
*/
public function setRequest(Request $request): void
{
$this->request = $request;
}
/**
* @return array
*/
public function getHeaders(): array
{
return $this->headers;
}
/**
* @param array $headers
*/
public function setHeaders(array $headers): void
{
$this->headers = $headers;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午10:54
*/
namespace Lib\iot;
use Psr\Http\Message\ResponseInterface;
class RefreshToken implements Request
{
private $refreshToken = '';
/**
* @param ResponseInterface $response
* @return AccessToken
*/
public function parseResponse(ResponseInterface $response)
{
$accessToken = new AccessToken();
$accessToken->parseResponse($response);
return $accessToken;
}
public function getReturnCode(): int
{
return 200;
}
public function isJson(): bool
{
return true;
}
public function getUrl(): string
{
return 'iocm/app/sec/v1.1.0/refreshToken';
}
public function getMethod(): string
{
return 'POST';
}
public function getFormData(): array
{
return [
'appId' => env('IOT_APP_ID'),
'secret' => env('IOT_APP_SECRET'),
'refreshToken' => $this->refreshToken
];
}
/**
* @return string
*/
public function getRefreshToken(): string
{
return $this->refreshToken;
}
/**
* @param string $refreshToken
*/
public function setRefreshToken(string $refreshToken): void
{
$this->refreshToken = $refreshToken;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/28
* Time: 上午10:49
*/
namespace Lib\iot;
use Psr\Http\Message\ResponseInterface;
interface Request
{
public function getReturnCode(): int;
public function getUrl(): string;
public function getMethod(): string;
public function getFormData(): array;
public function parseResponse(ResponseInterface $response);
public function isJson(): bool;
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午11:45
*/
namespace Lib\iot\command;
use Lib\iot\Request;
use Lib\ToHex;
class ChargerCommand extends Command
{
protected $command = '04';
private $type = 1;
private $portLogic = 0;
private $orderId = 0;
private $time = 0;
public function organizeMessage()
{
$nonce = ToHex::toHex(rand(1, 255), 1);
$length = 7 + strlen($this->message) / 2;
$this->message = ToHex::toHex($this->type, 1) . ToHex::toHex($this->portLogic, 1) . ToHex::toHex($this->orderId, 6) . ToHex::toHex($this->time, 2);
$this->message = 'ffaa' . $this->encrypt . $this->command . ToHex::toHex($length, 2) . $nonce . $this->message;
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @param int $type
*/
public function setType(int $type): void
{
$this->type = $type;
}
/**
* @return int
*/
public function getPortLogic(): int
{
return $this->portLogic;
}
/**
* @param int $portLogic
*/
public function setPortLogic(int $portLogic): void
{
$this->portLogic = $portLogic;
}
/**
* @return int
*/
public function getOrderId(): int
{
return $this->orderId;
}
/**
* @param int $orderId
*/
public function setOrderId(int $orderId): void
{
$this->orderId = $orderId;
}
/**
* @return int
*/
public function getTime(): int
{
return $this->time;
}
/**
* @param int $time
*/
public function setTime(int $time): void
{
$this->time = $time;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午11:38
*/
namespace Lib\iot\command;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
abstract class Command
{
protected $crc = '';
protected $command = '';
protected $encrypt = '04';
protected $length = 0;
protected $serviceId = '';
protected $method = 'Cmd_Res';
protected $paras = [];
protected $message = '';
abstract public function organizeMessage();
/**
* @return string
*/
public function getCrc(): string
{
return $this->crc;
}
/**
* @param string $crc
*/
public function setCrc(string $crc): void
{
$this->crc = $crc;
}
/**
* @return string
*/
public function getCommand(): string
{
return $this->command;
}
/**
* @param string $command
*/
public function setCommand(string $command): void
{
$this->command = $command;
}
/**
* @return string
*/
public function getEncrypt(): string
{
return $this->encrypt;
}
/**
* @param string $encrypt
*/
public function setEncrypt(string $encrypt): void
{
$this->encrypt = $encrypt;
}
/**
* @return int
*/
public function getLength(): int
{
return $this->length;
}
/**
* @param int $length
*/
public function setLength(int $length): void
{
$this->length = $length;
}
/**
* @return string
*/
public function getServiceId(): string
{
return $this->serviceId;
}
/**
* @param string $serviceId
*/
public function setServiceId(string $serviceId): void
{
$this->serviceId = $serviceId;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @param string $method
*/
public function setMethod(string $method): void
{
$this->method = $method;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* @param string $message
*/
public function setMessage(string $message): void
{
$this->message = $message;
}
public function getParas()
{
return json_encode($this->message);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/29
* Time: 上午11:34
*/
namespace Lib\iot\command;
use Illuminate\Support\Facades\Log;
use Lib\iot\AccessToken;
use Lib\iot\IotClient;
use Lib\iot\Request;
use Lib\ToHex;
use Psr\Http\Message\ResponseInterface;
/**
* 发送命令至iot设备
* Class Send
* @package Lib\iot\command
*/
class Send implements Request
{
protected $accessToken = '';
protected $appKey = '';
protected $contentType = 'application/json';
protected $appId = '';
protected $deviceId = '';
protected $command = '';
protected $commandInstance;
protected $callBackUrl = '';
protected $expireTime = 0;
protected $maxRetransmit = 2;
private $response;
/**
* Send constructor.
* @param Command $command
* @throws \Exception
*/
public function __construct(Command $command)
{
$this->appId = env('IOT_APP_ID');
$this->appKey = env('IOT_APP_ID');
$this->commandInstance = $command;
$body = $this->commandInstance->getMessage();
$nonce = ToHex::toHex(rand(1, 255), 1);
$length = 7 + strlen($body) / 2;
$message = 'ffaa' . $this->commandInstance->getEncrypt() . ToHex::toHex($length, 2) . $nonce . $body;
Log::debug($message);
if ($this->commandInstance->getEncrypt() === '04') {
$this->command = [
'serviceId' => $this->commandInstance->getServiceId(),
'method' => $this->commandInstance->getMethod(),
'paras' => ['downData' => $message],
];
} else {
throw new \Exception('no encrypt function');
}
}
public function getReturnCode(): int
{
return 201;
}
public
function send(): bool
{
Log::debug('send');
$iotClient = new IotClient($this);
$iotClient->setHeaders([
'app_key' => $this->appKey,
'Authorization' => 'Bearer ' . AccessToken::getAccessTokenCache(),
'Content-Type' => 'application/json'
]);
Log::debug($iotClient->getHeaders());
if ($iotClient->request($this->getReturnCode()) === true) {
$this->response = $iotClient->getResponse();
return true;
}
return false;
}
public
function getUrl(): string
{
return 'iocm/app/cmd/v1.4.0/deviceCommands';
}
public
function isJson(): bool
{
return true;
}
public
function getMethod(): string
{
return 'POST';
// TODO: Implement getMethod() method.
}
public
function getFormData(): array
{
return [
'deviceId' => $this->deviceId,
'command' => $this->command,
// 'callbackUrl' => $this->callBackUrl,
'expireTime' => $this->expireTime,
'maxRetransmit' => $this->maxRetransmit,
];
}
public
function parseResponse(ResponseInterface $response)
{
$this->response = $response;
}
/**
* @return string
*/
public
function getAccessToken(): string
{
return $this->accessToken;
}
/**
* @param string $accessToken
*/
public
function setAccessToken(string $accessToken): void
{
$this->accessToken = $accessToken;
}
/**
* @return string
*/
public
function getAppKey(): string
{
return $this->appKey;
}
/**
* @param string $appKey
*/
public
function setAppKey(string $appKey): void
{
$this->appKey = $appKey;
}
/**
* @return string
*/
public
function getContentType(): string
{
return $this->contentType;
}
/**
* @param string $contentType
*/
public
function setContentType(string $contentType): void
{
$this->contentType = $contentType;
}
/**
* @return string
*/
public
function getAppId(): string
{
return $this->appId;
}
/**
* @param string $appId
*/
public
function setAppId(string $appId): void
{
$this->appId = $appId;
}
/**
* @return string
*/
public
function getDeviceId(): string
{
return $this->deviceId;
}
/**
* @param string $deviceId
*/
public
function setDeviceId(string $deviceId): void
{
$this->deviceId = $deviceId;
}
/**
* @return array|string
*/
public
function getCommand()
{
return $this->command;
}
/**
* @param array|string $command
*/
public
function setCommand($command): void
{
$this->command = $command;
}
/**
* @return Command
*/
public
function getCommandInstance(): Command
{
return $this->commandInstance;
}
/**
* @param Command $commandInstance
*/
public
function setCommandInstance(Command $commandInstance): void
{
$this->commandInstance = $commandInstance;
}
/**
* @return string
*/
public
function getCallBackUrl(): string
{
return $this->callBackUrl;
}
/**
* @param string $callBackUrl
*/
public
function setCallBackUrl(string $callBackUrl): void
{
$this->callBackUrl = $callBackUrl;
}
/**
* @return int
*/
public
function getExpireTime(): int
{
return $this->expireTime;
}
/**
* @param int $expireTime
*/
public
function setExpireTime(int $expireTime): void
{
$this->expireTime = $expireTime;
}
/**
* @return int
*/
public
function getMaxRetransmit(): int
{
return $this->maxRetransmit;
}
/**
* @param int $maxRetransmit
*/
public
function setMaxRetransmit(int $maxRetransmit): void
{
$this->maxRetransmit = $maxRetransmit;
}
/**
* @return ResponseInterface
*/
public
function getResponse(): ResponseInterface
{
return $this->response;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/10
* Time: 上午10:44
*/
namespace Lib\iot\subscribe;
use Illuminate\Support\Facades\Log;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
class Business implements Request
{
private $notifyType = 'deviceDataChanged';
private $callBackUrl = '';
public function __construct()
{
$this->callBackUrl = route('deviceMessageReceiver', [], true);
$this->callBackUrl = str_replace('com', 'com:443', $this->callBackUrl);
}
public function getReturnCode(): int
{
return 201;
}
public function getUrl(): string
{
return 'iocm/app/sub/v1.2.0/subscriptions';
// TODO: Implement getUrl() method.
}
public function getMethod(): string
{
return 'POST';
}
public function getFormData(): array
{
return [
'callbackUrl' => $this->callBackUrl,
'notifyType' => $this->notifyType,
];
}
public function parseResponse(ResponseInterface $response)
{
Log::debug($response->getBody());
}
public function isJson(): bool
{
return true;
// TODO: Implement isJson() method.
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/10
* Time: 上午11:13
*/
namespace Lib\iot\subscribe;
use Illuminate\Support\Facades\Log;
use Lib\iot\Request;
use Psr\Http\Message\ResponseInterface;
class QueryMass implements Request
{
public function getReturnCode(): int
{
return 200;
}
public function getUrl(): string
{
return 'iocm/app/sub/v1.2.0/subscriptions';
}
public function getMethod(): string
{
return 'GET';
}
public function getFormData(): array
{
return [];
}
public function parseResponse(ResponseInterface $response)
{
Log::debug($response->getBody());
}
public function isJson(): bool
{
return false;
}
}
\ No newline at end of file
...@@ -37,7 +37,6 @@ $queueKeyWorker = 'queue_worker_check_port_charger_state'; ...@@ -37,7 +37,6 @@ $queueKeyWorker = 'queue_worker_check_port_charger_state';
$exchange = $myRabbitMq->getExchange(); $exchange = $myRabbitMq->getExchange();
$exchange->setName($myRabbitMq->getExchangeKey()); $exchange->setName($myRabbitMq->getExchangeKey());
$exchange->setType(AMQP_EX_TYPE_DIRECT); $exchange->setType(AMQP_EX_TYPE_DIRECT);
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/16
* Time: 上午10:26
*/
namespace Lib\send\command;
use Lib\send\Command;
class UpdateCommand extends Command
{
protected $headerCtrl = 'd2';
private $software = '';
private $hardware = '';
private $updateTime = '';
private $downloadUrl = '';
public function __construct(string $gatewayMac)
{
$this->clientUid = $gatewayMac;
}
public function getMessageBody(): string
{
$updateTime = sprintf('%08x', $this->updateTime);
$urlHex = '';
for ($i = 0; $i < strlen($this->downloadUrl); $i++) {
$hex = sprintf('%02x', ord($this->downloadUrl[$i]));
$urlHex .= $hex;
}
return $updateTime . $this->hardware . $this->software . $urlHex;
}
public function getClientId(): string
{
// TODO: Implement getClientId() method.
}
public function getClientUid(): string
{
return $this->clientUid;
}
/**
* @return string
*/
public function getSoftware(): string
{
return $this->software;
}
/**
* @param string $software
*/
public function setSoftware(string $software): void
{
$this->software = $software;
}
/**
* @return string
*/
public function getHardware(): string
{
return $this->hardware;
}
/**
* @param string $hardware
*/
public function setHardware(string $hardware): void
{
$this->hardware = $hardware;
}
/**
* @return string
*/
public function getUpdateTime(): string
{
return $this->updateTime;
}
/**
* @param string $updateTime
*/
public function setUpdateTime(string $updateTime): void
{
$this->updateTime = $updateTime;
}
/**
* @return string
*/
public function getDownloadUrl(): string
{
return $this->downloadUrl;
}
/**
* @param string $downloadUrl
*/
public function setDownloadUrl(string $downloadUrl): void
{
$this->downloadUrl = $downloadUrl;
}
}
\ No newline at end of file
...@@ -104,7 +104,8 @@ class WebGrant ...@@ -104,7 +104,8 @@ class WebGrant
'appid' => env('WX_APP_ID'), 'appid' => env('WX_APP_ID'),
'secret' => env('WX_APP_SECRET'), 'secret' => env('WX_APP_SECRET'),
'code' => $code, 'code' => $code,
'grant_type' => 'authorization_code'], 'grant_type' => 'authorization_code'
],
'http_errors' => false, 'http_errors' => false,
]); ]);
...@@ -155,12 +156,15 @@ class WebGrant ...@@ -155,12 +156,15 @@ class WebGrant
$wxAccessToken = $wxAccessToken->getAccessToken(); $wxAccessToken = $wxAccessToken->getAccessToken();
Log::debug($wxAccessToken);
$response = $this->client->request('POST', self::URL_USER_SUB, [ $response = $this->client->request('POST', self::URL_USER_SUB, [
'form_params' => [ 'form_params' => [
'access_token' => $wxAccessToken, 'access_token' => $wxAccessToken,
'openid' => $this->openid, 'openid' => $this->openid,
'lang' => config('wx.lang')], 'lang' => config('wx.lang')
],
'http_errors' => false, 'http_errors' => false,
]); ]);
...@@ -168,6 +172,12 @@ class WebGrant ...@@ -168,6 +172,12 @@ class WebGrant
$data = json_decode($response->getBody(), true); $data = json_decode($response->getBody(), true);
if (isset($data['errcode'])) {
Log::error($data['errmsg']);
abort(500, $data['errmsg']);
}
$this->wxUser = new User(); $this->wxUser = new User();
$this->wxUser->injectInfo($data); $this->wxUser->injectInfo($data);
...@@ -180,6 +190,8 @@ class WebGrant ...@@ -180,6 +190,8 @@ class WebGrant
$this->errorMessage = $data['errmsg']; $this->errorMessage = $data['errmsg'];
abort(500, $this->errorMessage);
$result = false; $result = false;
} }
......
...@@ -16,29 +16,29 @@ ...@@ -16,29 +16,29 @@
//}); //});
$router->get('/', function () use ($router) { $router->get('/', function () use ($router) {
echo str_random(32);
dd(phpinfo());
dd(\Lib\Gateway::getAllClientSessions()); dd(\Lib\Gateway::getAllClientSessions());
return $router->app->version(); return $router->app->version();
}); });
$router->group(['namespace' => '\Rap2hpoutre\LaravelLogViewer'],function () use ($router){ $router->group(['namespace' => '\Rap2hpoutre\LaravelLogViewer'], function () use ($router) {
$router->get('logs','LogViewerController@index'); $router->get('logs', 'LogViewerController@index');
}); });
$api = app('Dingo\Api\Routing\Router'); $api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/wx'], function ($api) { $api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/wx'], function ($api) {
$api->post('notice/update', 'Update\UpdateController@noticeUpdate');
$api->post('firmware', 'Update\UpdateController@upload');
$api->post('user', ['as' => 'wx.token', 'uses' => 'Wx\AccessController@getUserInfo']); $api->post('user', ['as' => 'wx.token', 'uses' => 'Wx\AccessController@getUserInfo']);
//微信网页授权getcode //微信网页授权getcode
...@@ -98,18 +98,17 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/ ...@@ -98,18 +98,17 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/
$api->get('user/order/using', ['uses' => 'User\StatisticController@getUserUsingOrder']); $api->get('user/order/using', ['uses' => 'User\StatisticController@getUserUsingOrder']);
//token解析 //token解析
$api->post('token/parse',['uses' => 'Tool\TokenController@parse']); $api->post('token/parse', ['uses' => 'Tool\TokenController@parse']);
//更换口子 //更换口子
$api->post('port/change', ['uses' => 'Charger\ChangePortController@change']); $api->post('port/change', ['uses' => 'Charger\ChangePortController@change']);
$api->get('user/recharge/orders',['uses' =>'User\OrderController@getRechargeOrder']); $api->get('user/recharge/orders', ['uses' => 'User\OrderController@getRechargeOrder']);
$api->post('user/withdraw',['uses' => 'User\WithDrawController@withDraw']); $api->post('user/withdraw', ['uses' => 'User\WithDrawController@withDraw']);
$api->get('user/code/withdraw', ['uses' => 'User\WithDrawController@getCode']);
$api->get('user/code/withdraw',['uses' => 'User\WithDrawController@getCode']);
// 查找附近的站点 // 查找附近的站点
...@@ -131,8 +130,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/ ...@@ -131,8 +130,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1', 'prefix' => 'api/
$api->get('send', 'TestController@send'); $api->get('send', 'TestController@send');
$api->any('receiver','Wx\ReceiverController@index'); $api->any('receiver', 'Wx\ReceiverController@index');
}); });
Bag Attributes
localKeyID: E2 22 EC 85 05 50 93 61 45 50 EA 4C 0D 72 95 38 AC CC C8 73
subject=/C=CN/ST=GD/L=SZ/O=Huawei/OU=CN/CN=www.smarthome-demo.com
issuer=/C=CN/ST=GD/L=SZ/O=Huawei/OU=CN/CN=IOT
-----BEGIN CERTIFICATE-----
MIIDVjCCAj6gAwIBAgIJAJCrWqXqdcxuMA0GCSqGSIb3DQEBCwUAMFMxCzAJBgNV
BAYTAkNOMQswCQYDVQQIEwJHRDELMAkGA1UEBxMCU1oxDzANBgNVBAoTBkh1YXdl
aTELMAkGA1UECxMCQ04xDDAKBgNVBAMTA0lPVDAeFw0xNjA1MDQxMjM1NTRaFw0y
NjA1MDIxMjM1NTRaMGYxCzAJBgNVBAYTAkNOMQswCQYDVQQIEwJHRDELMAkGA1UE
BxMCU1oxDzANBgNVBAoTBkh1YXdlaTELMAkGA1UECxMCQ04xHzAdBgNVBAMTFnd3
dy5zbWFydGhvbWUtZGVtby5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQDXabyOJ/boRw8kqMOGzlVqoq6eSeeeeYPni7QL3IlTYCIP4AdZ3W4S4Tki
tSE7YwwVDlIipEhqDVHthR2YPU7sYELhqrDqxHtjXGnMEmmWCvauV6kstrMSQMKT
DFD3ATlJwVGqBRw81GtpRSeo2lCibXMk8Y4mZJy1d7U70VgRaq/Vhjv6oTPcFLsW
IVevMuMwZj3/+C4oLIr6WARo84stMhEFMR0IIbaVbmy8sbt28bq33fz6+n5V2R+g
r97DbQ9wEtb+q2aPPyGYJke3F4j8F/Kw0QTlYcnpO6+Ghs37Iv10r6cN7meigD5/
gYr8O1VAFmeIqldKjIPQkoFFfOXBAgMBAAGjGjAYMAkGA1UdEwQCMAAwCwYDVR0P
BAQDAgXgMA0GCSqGSIb3DQEBCwUAA4IBAQCQebgg89ZZMW9R3yQ7tSeOVCt2M/tO
gZRaLrKMxWRJZngQeg+SVeJvkXcxlRTgwqElcVG/i7zguZjO/ff39Y8MPcWAaNIy
yTmt7kuP7YAS6Jf7unUA2y76mXsPiFJAOMLVm/CO+/BP2a0HJGm+6B+1TZzBZeQl
zeOxesFrEAJxopBkHpmgQNJM/E/5AAgrI1gNB5DrG2Zn3/M0FF+FLDv9QGWZJ5ay
R1Wn5WCMpPqFm6PP7qG2n+a4wzqxjaeVBBmv6X2cvHNVVUZ/zDdIMOtzQs6KMqWo
wZIpeAax6+fhzGh3X482oJRpSS8ZNSFBycN9tYlk69NuPB9bD6Kxhnrv
-----END CERTIFICATE-----
Bag Attributes
localKeyID: E2 22 EC 85 05 50 93 61 45 50 EA 4C 0D 72 95 38 AC CC C8 73
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDXabyOJ/boRw8k
qMOGzlVqoq6eSeeeeYPni7QL3IlTYCIP4AdZ3W4S4TkitSE7YwwVDlIipEhqDVHt
hR2YPU7sYELhqrDqxHtjXGnMEmmWCvauV6kstrMSQMKTDFD3ATlJwVGqBRw81Gtp
RSeo2lCibXMk8Y4mZJy1d7U70VgRaq/Vhjv6oTPcFLsWIVevMuMwZj3/+C4oLIr6
WARo84stMhEFMR0IIbaVbmy8sbt28bq33fz6+n5V2R+gr97DbQ9wEtb+q2aPPyGY
Jke3F4j8F/Kw0QTlYcnpO6+Ghs37Iv10r6cN7meigD5/gYr8O1VAFmeIqldKjIPQ
koFFfOXBAgMBAAECggEAbfdcenWMZidgY6aDql3K3RUPb17rDsuZuqpmz2dV82ov
+Uq0dfvEJX80W7N7s4VstZMJ+wVCsmD6YfaClSU3FRRPEETC7BZBpweWOsdrf105
cObvRhQ+diL5MXgoHPBS/oPh3JmfQK5v5t2W0Wwhncmh7koh9xeFqF3j9xV3j+um
cTEq0IAxvlaWaR4fYq7xy/U6I8TuDsrHTnPgp8CdHSMMQ0oj+SxMCJMorYjRkHrx
VghrR/ZEcLCdQD43uNDT5YqsfX9GjkvbqAaTf/ZqgN9DRexEKi0uRzqyPxyHSL6Y
dmEExGI6AKGou8hqj0qOd+5ifHVECcZgsEODdFsQAQKBgQD6tgCwkwUarYPRkEC/
l2JtI9/1LZrdY4dcGAZtAh5uSptBC/+oXT1l8yyYs2WBxOz2EzH8cRnhXTzbj5tB
r+xqn6NvtxYjm6Hs4/+pMXTX0lwuHspLwSplr5B71eAOOnuokusYtI/UIu87gDUe
HjuVQk8VOnR9bjBlO3xSnWk6cQKBgQDb9RpTr8JHeLHPM+/0hWbFLWeCDMU+f2et
SHY0Y8MUFmAjDfUK3PajueRnrlI7Nz+kjywNorf+foJy811l7dnrh5m/nHWFcwtw
TBGYeRJj2rEVs5NRRaEbGeQPIYprPGKEWLJZ6G+bMIKdpS6BAlJI2TI+wZod8FvL
ZuYJ/WvoUQKBgQClFccqfgS0ZmEQUx5vii1jlGXaOedptCnjeGZyzRxgn3vPvyjf
IlZVlWReQHKsmpE2D7mwcoEKJqz2Hn+rJz5Tjz69Rx+q3sYnCJLGRCyeGIReUiP+
8fkK8CoBgPmCJPxcKjHoGK1EkKRa17ciV+IADKOqZM1j8nSnlB3vAHvT4QKBgAN7
2FTm/b7ADKDpg61tx3jsBS2sIhuhTPUTpruhsN9Kk286s1zerxFcyl9SBX9mmp1y
nxIAN8XSHyLO8/W/VKpEVY0RX1MjxVSb/9NYZ5ApUJC1bWnmHm0ddd0/fL/CDxVl
ij2eTtY4aHkyuo/Uh5Uby43u5w/+VJXeJVqXJvRhAoGAAuPkfKD6+OdB2HNREpK7
jJ4b0dFygj8EJf7sxxM/QARAxAUVMTIO+oE3sQCfAdT19YR/3bPY1VFZB6Z18mc6
tD0UfdzUFTs0XAtT5P/zHSsoRSWmFMIEPXTjjE+42MaXnHi2Ul7bqCHr8rr1hIkB
DY5UCch6GiVKxDjWpHb+J4s=
-----END PRIVATE KEY-----
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment