221 lines
7.8 KiB
PHP
221 lines
7.8 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: Administrator
|
|
* Date: 2021/6/1 0001
|
|
* Time: 13:45
|
|
*/
|
|
|
|
namespace app\controllers\channel;
|
|
|
|
use Yii;
|
|
use app\models\common\Store;
|
|
use app\models\common\Order;
|
|
use app\models\common\Printing;
|
|
|
|
class QueuingController extends CommonController{
|
|
private $shop_id;
|
|
public function init(){
|
|
parent::init();
|
|
$this->shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
|
$this->shop_id=$this->shop_id?:0;
|
|
}
|
|
//桌位类型
|
|
public function actionTypeList(){
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->shop_id;
|
|
$page=$result['page'];
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$table=(new \yii\db\Query())
|
|
->from('{{%ybwm_queuing_type}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId]);
|
|
if(!$page){
|
|
$list=$table->orderBy('sort asc,id desc')->all();
|
|
$state=$result['state'];
|
|
$timeType=$result['timeType'];
|
|
$timeArr=$this->timeArr[$timeType];
|
|
$keyword=$result['keyword'];
|
|
for($i=0;$i<count($list);$i++){
|
|
|
|
$count=(new \yii\db\Query())
|
|
->from('{{%ybwm_queuing}}')
|
|
->where(['tableId'=>$list[$i]['id'],'deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId]);
|
|
if($state==1){
|
|
$count->andWhere('state=1');
|
|
}
|
|
if($state==2){
|
|
$count->andWhere('state=2');
|
|
}
|
|
if($state==3){
|
|
$count->andWhere('state in (3,4)');
|
|
}
|
|
if($timeType){
|
|
$count->andWhere('createdAt>=:startTime AND createdAt<=:endTime',[':startTime'=>$timeArr['startTime'],':endTime'=>$timeArr['endTime']]);
|
|
}
|
|
if($keyword){
|
|
$count->andWhere(['or',['like','tel',$keyword],['like','code',$keyword]]);
|
|
}
|
|
$list[$i]['orderNum']=$count->count()?:0;
|
|
}
|
|
return $this->result(1, '成功',$list);
|
|
}
|
|
$list=$table->offset($num)
|
|
->limit($limit)->orderBy('sort asc,id desc')->all();
|
|
$count=$table->count();
|
|
return $this->result(1, '成功',$list,$count);
|
|
}
|
|
//保存桌位类型
|
|
public function actionSaveType(){
|
|
$result=axios_request();
|
|
$request = Yii::$app->request;
|
|
$storeId=$result['storeId']?:$this->shop_id;
|
|
if($request->isGet){
|
|
$info=(new \yii\db\Query())
|
|
->from('{{%ybwm_queuing_type}}')
|
|
->where('id=:id',[':id'=>$result['id']])->one();
|
|
return $this->result(1, '成功',$info);
|
|
}
|
|
if(!$result['name']){
|
|
return $this->result(2,'名称不能为空!');
|
|
}
|
|
if($result['max']<$result['min']){
|
|
return $this->result(2,'最大值不能小于最小值!');
|
|
}
|
|
if(!$result['minute']){
|
|
return $this->result(2,'时间不能为空!');
|
|
}
|
|
$data['name']=$result['name'];
|
|
$data['min']=$result['min'];
|
|
$data['max']=$result['max'];
|
|
$data['minute']=$result['minute'];
|
|
$data['sort']=$result['sort'];
|
|
$data['storeId']=$storeId;
|
|
if($result['id']){
|
|
$data['changeAt']=time();
|
|
$re = Yii::$app->db->createCommand()->update('{{%ybwm_queuing_type}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['uniacid']=$this->wqData['uniacid'];
|
|
$data['createdAt']=time();
|
|
$re = Yii::$app->db->createCommand()->insert('{{%ybwm_queuing_type}}', $data)->execute();
|
|
}
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
//修改桌位类型
|
|
public function actionModifyType(){
|
|
$post=axios_request();
|
|
if($post['type']==1){
|
|
//显示隐藏
|
|
$data['display']=$post['display'];
|
|
}
|
|
if($post['type']==2){
|
|
//删除
|
|
$data['deleteAt']=time();
|
|
}
|
|
$data['changeAt']=time();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_queuing_type}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
|
|
//排队列表
|
|
public function actionQueuingList(){
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->shop_id;
|
|
$page=$result['page']?:1;
|
|
$tableId=$result['typeId'];
|
|
$state=$result['state'];
|
|
$timeType=$result['timeType'];
|
|
$timeArr=$this->timeArr[$timeType];
|
|
$keyword=$result['keyword'];
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$table=(new \yii\db\Query())
|
|
->select('a.origin,a.id,a.code,a.name,from_unixtime(a.changeAt) changeAt,from_unixtime(a.createdAt) createdAt,a.people,a.tel,a.state,a.day,b.userName,b.portrait,a.userId')
|
|
->from('{{%ybwm_queuing}} as a')
|
|
->leftJoin('{{%ybwm_member}} as b','a.userId=b.id')
|
|
->where(['a.deleteAt'=>0,'a.uniacid'=>$this->wqData['uniacid'],'a.storeId'=>$storeId]);
|
|
if($tableId){
|
|
$table->andWhere('a.tableId='.$tableId);
|
|
}
|
|
if($state==1){
|
|
$table->andWhere('a.state=1');
|
|
}
|
|
if($state==2){
|
|
$table->andWhere('a.state=2');
|
|
}
|
|
if($state==3){
|
|
$table->andWhere('a.state in (3,4)');
|
|
}
|
|
if($timeArr){
|
|
$table->andWhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',[':startTime'=>$timeArr['startTime'],':endTime'=>$timeArr['endTime']]);
|
|
}
|
|
if($keyword){
|
|
$table->andWhere(['or',['like','a.tel',$keyword],['like','a.code',$keyword]]);
|
|
}
|
|
$list=$table->offset($num)
|
|
->limit($limit)->orderBy('a.id desc')->all();
|
|
$count=$table->count();
|
|
return $this->result(1, '成功',$list,$count);
|
|
}
|
|
//修改取号信息
|
|
public function actionModifyQueuing() {
|
|
$result=axios_request();
|
|
$queuing=(new \yii\db\Query())
|
|
->from('{{%ybwm_queuing}}')
|
|
->where('id=:id',[':id'=>$result['id']])->one();
|
|
if (!$queuing) {
|
|
return $this->result(2, '取号信息不存在!');
|
|
}
|
|
|
|
if ($result['type'] == 'eat') {
|
|
$data['state'] = 2;
|
|
} elseif ($result['type'] == 'skip') {
|
|
$data['state'] = 3;
|
|
} elseif ($result['type'] == 'cancel') {
|
|
$data['state'] = 4;
|
|
} elseif ($result['type'] == 'del') {
|
|
$data['deleteAt'] = time();
|
|
} elseif ($result['type'] == 'print') {
|
|
//打印
|
|
Printing::queuingPrint($result['id']);
|
|
return $this->result(1, '成功');
|
|
}
|
|
$data['changeAt']=time();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_queuing}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
if ($res) {
|
|
Order::getQueuingScreenInfo($queuing['storeId']);
|
|
return $this->result(1, '成功');
|
|
} else {
|
|
return $this->result(2, '失败');
|
|
}
|
|
}
|
|
|
|
//呼叫
|
|
public function actionCallService() {
|
|
$result=axios_request();
|
|
if (!$result['id']) {
|
|
return $this->result(2, '参数错误');
|
|
}
|
|
$data['changeAt']=time();
|
|
Yii::$app->db->createCommand()->update('{{%ybwm_queuing}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
$res=Order::queuingCall($result['id']);
|
|
if ($res) {
|
|
return $this->result(1, '成功',$res);
|
|
} else {
|
|
return $this->result(2, '失败');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} |