203 lines
7.3 KiB
PHP
203 lines
7.3 KiB
PHP
![]() |
<?php
|
|||
|
/**
|
|||
|
* Created by PhpStorm.
|
|||
|
* User: Administrator
|
|||
|
* Date: 2021/6/1 0001
|
|||
|
* Time: 15:04
|
|||
|
*/
|
|||
|
|
|||
|
namespace app\controllers\channelApi;
|
|||
|
|
|||
|
use app\models\common\Config;
|
|||
|
use app\models\common\Printing;
|
|||
|
use app\models\common\Message;
|
|||
|
use app\models\common\Power;
|
|||
|
use Yii;
|
|||
|
class QueuingController extends CommonController{
|
|||
|
public $enableCsrfValidation = false;
|
|||
|
function init(){
|
|||
|
parent::init();
|
|||
|
$power=Power::getPayPower($this->wqData['uniacid'],'queuing');
|
|||
|
if(!$power){
|
|||
|
echo json_encode(['code'=>2,'msg'=>'暂无权限']);die;
|
|||
|
}
|
|||
|
}
|
|||
|
//餐桌类型列表
|
|||
|
public function actionQueuingType() {
|
|||
|
$result=axios_request();
|
|||
|
$uniacid=$this->wqData['uniacid'];
|
|||
|
$storeId=$result['storeId'];
|
|||
|
if (!$storeId) {
|
|||
|
return $this->result(2,'商家信息错误');
|
|||
|
}
|
|||
|
$queuingType=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing_type}}')
|
|||
|
->where(['deleteAt'=>0,'uniacid'=>$uniacid,'storeId'=>$storeId])->orderBy('max asc')->all();
|
|||
|
if (!$queuingType) {
|
|||
|
return $this->result(2,'暂无桌位信息');
|
|||
|
}
|
|||
|
$day = date('Y-m-d');
|
|||
|
foreach ($queuingType as $key => $value) {
|
|||
|
$minute = 0;
|
|||
|
$count=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing}}')
|
|||
|
->where(['storeId' => $storeId, 'tableId' => $value['id'], 'day' => $day, 'state' => 1])->count();
|
|||
|
if ($count) {
|
|||
|
$minute = $value['minute'] * $count;
|
|||
|
}
|
|||
|
$queuingType[$key]['waitNum'] = $count;
|
|||
|
$queuingType[$key]['waitMinute'] = $minute;
|
|||
|
}
|
|||
|
$data['list']=$queuingType;
|
|||
|
$set = Config::getStoreSet('queuing', $storeId);
|
|||
|
$data['other']=['notice'=>$set['details']];
|
|||
|
return $this->result(1, '成功',$data);
|
|||
|
}
|
|||
|
|
|||
|
//取号
|
|||
|
public function actionTakeNumber() {
|
|||
|
$request = Yii::$app->request;
|
|||
|
$result=axios_request();
|
|||
|
$userId=$this->wqData['userId'];
|
|||
|
$appType = $this->wqData['appType'];
|
|||
|
$now=time();
|
|||
|
$uniacid=$this->wqData['uniacid'];
|
|||
|
if($request->isGet){
|
|||
|
return $this->result(2, '请求异常');
|
|||
|
}
|
|||
|
if (!$result['tableId']) {
|
|||
|
return $this->result(2, '餐桌类型ID不能为空!!!');
|
|||
|
}
|
|||
|
$tableInfo=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing_type}}')
|
|||
|
->where(['id'=>$result['tableId']])->one();
|
|||
|
$day = date('Y-m-d');
|
|||
|
$myNumber=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing}}')
|
|||
|
->where(['userId' => $userId,'deleteAt'=>0,'storeId' => $tableInfo['storeId'], 'day' => $day])->orderBy('id desc')->one();
|
|||
|
if ($myNumber['state'] == 1) {
|
|||
|
return $this->result(2, '您有排队中的号,不可重复取号');
|
|||
|
}
|
|||
|
$data['origin'] = $appType;
|
|||
|
$data['storeId'] = $tableInfo['storeId'];
|
|||
|
$data['name'] = $tableInfo['name'];
|
|||
|
$data['tableId'] = $result['tableId'];
|
|||
|
$data['userId'] = $userId;
|
|||
|
$data['people'] = $result['people'] ?: 1;
|
|||
|
$data['tel'] = $result['tel'];
|
|||
|
$data['state'] = 1;
|
|||
|
$data['createdAt'] = $now;
|
|||
|
$data['day'] = $day;
|
|||
|
$data['uniacid'] =$uniacid;
|
|||
|
$data['changeAt']=time();
|
|||
|
//$rst = pdo_get('ybcy_queuing', array('storeId' => $_GPC['storeId'], 'day' => $day, 'deleteAt' => 0), array('id', 'code'));
|
|||
|
$rst=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing}}')
|
|||
|
->where(['storeId' => $tableInfo['storeId'], 'day' => $day])->orderBy('id desc')->all();
|
|||
|
if ($rst) {
|
|||
|
$str = substr($rst[0]['code'], 1);
|
|||
|
$preg = '/[0]*/';
|
|||
|
$result1 = preg_replace($preg, '', $str, 1);
|
|||
|
$num = $result1 + 1;
|
|||
|
$code = substr("000" . $num, -4);
|
|||
|
$data['code'] = 'A' . $code;
|
|||
|
} else {
|
|||
|
$data['code'] = "A0001";
|
|||
|
}
|
|||
|
$res =Yii::$app->db->createCommand()->insert('{{%ybwm_queuing}}', $data)->execute();
|
|||
|
$codeId = Yii::$app->db->getLastInsertID();
|
|||
|
if($res){
|
|||
|
$set = Config::getStoreSet('queuing', $tableInfo['storeId']);
|
|||
|
if($set['orderPrint']==1){
|
|||
|
Printing::queuingPrint($codeId);
|
|||
|
}
|
|||
|
Message::queuingOrder($codeId);
|
|||
|
return $this->result(1, '操作成功',$codeId);
|
|||
|
}else{
|
|||
|
return $this->result(2, '操作失败');
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//排队详情
|
|||
|
public function actionTakeNumberInfo() {
|
|||
|
$result=axios_request();
|
|||
|
$day = date('Y-m-d');
|
|||
|
$info=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing}}')
|
|||
|
->where(['id'=>$result['id']])->one();
|
|||
|
if(!$info){
|
|||
|
return $this->result(2, '获取详情失败');
|
|||
|
}
|
|||
|
$table=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing_type}}')
|
|||
|
->where(['id'=>$info['tableId']])->one();
|
|||
|
$minute = 0;
|
|||
|
$count=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing}}')
|
|||
|
->where(['storeId' => $info['storeId'], 'tableId' => $info['tableId'], 'day' => $day, 'state' => 1])->count();
|
|||
|
if ($count) {
|
|||
|
$minute = $table['minute'] * $count;
|
|||
|
}
|
|||
|
$alreadyWaiting = ceil((time() - $info['createdAt']) / 60);
|
|||
|
$info['waitNum'] = $count;
|
|||
|
$info['waitMinute'] = $minute;
|
|||
|
$info['alreadyWaiting'] = $alreadyWaiting;
|
|||
|
$set = Config::getStoreSet('queuing', $info['storeId']);
|
|||
|
$info['notice']=$set['details'];
|
|||
|
return $this->result(1, '成功', $info);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//我的排队
|
|||
|
public function actionMyTakeNumber() {
|
|||
|
$result=axios_request();
|
|||
|
$userId=$this->wqData['userId'];
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_queuing}}', ['state'=>4],'userId=:userId AND state=1 AND day!=:day AND deleteAt=0',[':userId'=>$userId,':day'=>date('Y-m-d')])->execute();
|
|||
|
$page=$result['page']?:1;
|
|||
|
$num=($page-1)*10;
|
|||
|
$limit=10;
|
|||
|
$table=(new \yii\db\Query())
|
|||
|
->select('a.createdAt,a.code,a.id,a.people,a.state,a.name,b.name as storeName,b.icon as logo,a.storeId')
|
|||
|
->from('{{%ybwm_queuing}} as a')
|
|||
|
->leftJoin('{{%ybwm_store}} as b','a.storeId=b.id')
|
|||
|
->where(['a.deleteAt'=>0,'a.userDeleteAt'=>0,'a.userId'=>$userId]);
|
|||
|
$list=$table->offset($num)
|
|||
|
->limit($limit)->orderBy('a.id desc')->all();
|
|||
|
return $this->result(1, '成功',$list);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//取消/删除排队
|
|||
|
public function actionModifyTakeNumber() {
|
|||
|
$request = Yii::$app->request;
|
|||
|
$result=axios_request();
|
|||
|
if($request->isGet || !$result['type']){
|
|||
|
return $this->result(2, '请求异常');
|
|||
|
}
|
|||
|
$info=(new \yii\db\Query())
|
|||
|
->from('{{%ybwm_queuing}}')
|
|||
|
->where(['id'=>$result['id']])->one();
|
|||
|
if (!$info) {
|
|||
|
return $this->result(2, '数据不存在,或已被删除');
|
|||
|
}
|
|||
|
if($result['type']=='cancel'){
|
|||
|
$data['state']=4;
|
|||
|
}
|
|||
|
if($result['type']=='delete'){
|
|||
|
$data['userDeleteAt']=time();
|
|||
|
}
|
|||
|
$data['changeAt']=time();
|
|||
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_queuing}}', $data,['id'=>$result['id']])->execute();
|
|||
|
if($res){
|
|||
|
return $this->result(1, '成功');
|
|||
|
}else{
|
|||
|
return $this->result(2, '失败');
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|