|
@@ -6,8 +6,10 @@ define('BASE_ROOT_PATH',str_replace('/application/index/controller','',dirname(_
|
|
|
require_once(BASE_ROOT_PATH . '/extend/queue.php');
|
|
|
require_once(BASE_ROOT_PATH . '/extend/queue.logic.php');
|
|
|
|
|
|
+use app\index\model\BoxActionModel;
|
|
|
use app\index\model\CabinetModel;
|
|
|
use app\index\model\BoxModel;
|
|
|
+use app\index\model\OrderModel;
|
|
|
use think\Session;
|
|
|
use QueueClient;
|
|
|
use QueueServer;
|
|
@@ -20,6 +22,12 @@ class Cabinet extends Base
|
|
|
*/
|
|
|
public function check_fcode(){
|
|
|
$code = input('param.code');
|
|
|
+ $OrderModel = new OrderModel();
|
|
|
+ $result = $OrderModel->check_fcode($code);
|
|
|
+ if($result['code'] != 1){
|
|
|
+ return json(json_error_exception('1009'));
|
|
|
+ }
|
|
|
+ json_success($result['data']);
|
|
|
}
|
|
|
/**
|
|
|
* 自提柜向服务器上报
|
|
@@ -37,6 +45,12 @@ class Cabinet extends Base
|
|
|
$trunk = input('param.trunk');
|
|
|
$cabinet = input('param.cabinet');
|
|
|
$state = input('param.state');
|
|
|
+
|
|
|
+ $result = $this->change_status($cabinet , $trunk , $state);
|
|
|
+ if($result['code'] != 1){
|
|
|
+ return json(json_error_exception('1006'));
|
|
|
+ }
|
|
|
+ json_success('');
|
|
|
}
|
|
|
/**
|
|
|
* 自提柜批量生产
|
|
@@ -59,7 +73,10 @@ class Cabinet extends Base
|
|
|
json_success([],'success');
|
|
|
}
|
|
|
|
|
|
- public function open_box()
|
|
|
+ /**
|
|
|
+ * 开启箱门
|
|
|
+ */
|
|
|
+ public function OpenBox()
|
|
|
{
|
|
|
session('start','1');
|
|
|
$cabinet_number = input('param.cabinet_number');
|
|
@@ -72,18 +89,53 @@ class Cabinet extends Base
|
|
|
'ret_queue' => $sid
|
|
|
];
|
|
|
|
|
|
- $queue_name = 'access_wait_oper';
|
|
|
- QueueClient::push($queue_name,'lredis',6379,'open_box',$params);
|
|
|
+ $queue_name = 'access_wait_open';
|
|
|
+ $this->push_queue('access_wait_open','OpenBox',$params);
|
|
|
+
|
|
|
+ $content = $this->wait_ret($sid,'lredis',6379);
|
|
|
+
|
|
|
+ if($content['value'] == 'ok'){
|
|
|
+ $this->box_action_record($cabinet_number , $box_number , 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 关闭箱门
|
|
|
+ */
|
|
|
+ public function LockBox()
|
|
|
+ {
|
|
|
+ session('start','1');
|
|
|
+ $cabinet_number = input('param.cabinet_number');
|
|
|
+ $box_number = input('param.box_number');
|
|
|
+ $sid = session_id();
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ 'cabinet_number' => $cabinet_number,
|
|
|
+ 'box_number' => $box_number,
|
|
|
+ 'ret_queue' => $sid
|
|
|
+ ];
|
|
|
|
|
|
+ $this->push_queue('access_wait_close','close_box',$params);
|
|
|
$content = $this->wait_ret($sid,'lredis',6379);
|
|
|
|
|
|
+ if($content['value'] == 'ok'){
|
|
|
+ $this->box_action_record($cabinet_number , $box_number , 2);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private function testSend($queue_name,$value) {
|
|
|
QueueClient::push($queue_name,'lredis',6379,'open_box_return',['value' => 'ok']);
|
|
|
|
|
|
}
|
|
|
+ /**
|
|
|
+ * queue推送
|
|
|
+ */
|
|
|
+ private function push_queue($queue_name,$key,$params){
|
|
|
+ QueueClient::push($queue_name,'lredis',6379,$key,$params);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * queue监听队列等待
|
|
|
+ */
|
|
|
private function wait_ret($queue_name,$host,$name)
|
|
|
{
|
|
|
$worker = new QueueServer($queue_name,$host,$name);
|
|
@@ -95,9 +147,8 @@ class Cabinet extends Base
|
|
|
pcntl_signal_dispatch();
|
|
|
try
|
|
|
{
|
|
|
- $content = $worker->pop($queues, 1);
|
|
|
+ $content = $worker->pop($queues, 0);
|
|
|
return $content;
|
|
|
-
|
|
|
}
|
|
|
catch (Exception $e)
|
|
|
{
|
|
@@ -108,36 +159,55 @@ class Cabinet extends Base
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
+ * 更新箱子时间
|
|
|
+ */
|
|
|
+
|
|
|
+ /**
|
|
|
* 自提柜箱子修改状态
|
|
|
*/
|
|
|
- public function change_status(){
|
|
|
- $cabinet_number = input('param.cabinet_number');
|
|
|
- $box_number = input('param.box_number');
|
|
|
- $status = input('param.status');
|
|
|
+ private function change_status($cabinet_number , $box_number , $status){
|
|
|
$BoxModel = new BoxModel();
|
|
|
$box = $BoxModel->getOneCabinetBox($cabinet_number,$box_number);
|
|
|
if(empty($cabinet)){
|
|
|
return json(json_error_exception(1008));
|
|
|
}
|
|
|
- if($box['status'] == $status){
|
|
|
- json_success('','success');
|
|
|
+ if($status == $cabinet['status']){
|
|
|
+ return msg(1, '', 'success');
|
|
|
}
|
|
|
+ $where['cabinet_number'] = $cabinet_number;
|
|
|
+ $where['box_number'] = $box_number;
|
|
|
+ $update['box_status'] = $status;
|
|
|
+ return $BoxModel->editData($where,$update);
|
|
|
+ }
|
|
|
+ public function test(){
|
|
|
+ $cabinet_number = input('param.cabinet_number');
|
|
|
+ $box_number = input('param.box_number');
|
|
|
+ $order_sn = input('param.order_sn');
|
|
|
+ $result = $this->box_bind_order($cabinet_number , $box_number , $order_sn);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 自提柜箱子绑定订单号
|
|
|
*/
|
|
|
- public function box_bind_order(){
|
|
|
- $where['cabinet_number'] = input('param.cabinet_number');
|
|
|
- $where['box_number'] = input('param.box_number');
|
|
|
-
|
|
|
- $update['enter_time'] = date('Y-m-d H:i:s');
|
|
|
- $update['order_sn'] = input('param.order_sn');
|
|
|
+ private function box_bind_order($cabinet_number , $box_number , $order_sn){
|
|
|
+ $where['cabinet_number'] = $cabinet_number;
|
|
|
+ $where['box_number'] = $box_number;
|
|
|
+ $update['order_sn'] = $order_sn;
|
|
|
+ $update['box_status'] = 2;
|
|
|
|
|
|
$BoxModel = new BoxModel();
|
|
|
- $result = $BoxModel->editData($where,$update);
|
|
|
- if($result['code'] != 1){
|
|
|
- return json(json_error_exception('1006',$result['msg']));
|
|
|
- }
|
|
|
- json_return(200,[],'success');
|
|
|
+ return $BoxModel->editData($where,$update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录箱子开启/关闭
|
|
|
+ */
|
|
|
+ private function box_action_record($cabinet_number , $box_number , $type){
|
|
|
+ $BoxActionModel = new BoxActionModel();
|
|
|
+ $params['cabinet_number'] = $cabinet_number;
|
|
|
+ $params['box_number'] = $box_number;
|
|
|
+ $params['type'] = $type;
|
|
|
+ $params['datetime'] = date("Y-m-d H:i:s");
|
|
|
+ $BoxActionModel->save($params);
|
|
|
}
|
|
|
}
|