149 lines
6.3 KiB
PHP
149 lines
6.3 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\Config;
|
|
use app\models\common\Order;
|
|
use app\models\common\Store;
|
|
|
|
class ReserveController extends CommonController{
|
|
public $enableCsrfValidation = false;
|
|
private $shop_id;
|
|
function init(){
|
|
parent::init();
|
|
$this->shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
|
$this->shop_id=$this->shop_id?:0;
|
|
}
|
|
//商家订单列表
|
|
public function actionOrder(){
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->shop_id;
|
|
$month=$result['month'];
|
|
$storeSet = Config::getStoreSet('appointment', $storeId);
|
|
$weekSet = $storeSet['week'] ?: [1, 2, 3, 4, 5, 6, 7];
|
|
$timeArr=getMonth(strtotime($month));
|
|
for($i=0;$i<count($timeArr);$i++){
|
|
$num=(new \yii\db\Query())
|
|
->from('{{%ybwm_appointment}}')
|
|
->where("state!=1 AND deleteAt=0 AND storeId=:storeId", [':storeId' => $storeId])
|
|
->andWhere('serviceAt>=:startTime AND serviceAt<=:endTime',[':startTime'=>strtotime($timeArr[$i]."00:00:00"),':endTime'=>strtotime($timeArr[$i]."23:59:59")])
|
|
->count()?:0;
|
|
$weekNum = date("w", strtotime($timeArr[$i]));
|
|
$weekNum2 = $weekNum == 0 ? 7 : $weekNum;
|
|
$data[]=array(
|
|
'time'=>$timeArr[$i],
|
|
'num'=>$num,
|
|
'isAppointment'=>in_array($weekNum2, $weekSet) == true ? 1 : 2
|
|
);
|
|
}
|
|
return $this->result(1, '操作成功!',$data);
|
|
// $region =(new \yii\db\Query())
|
|
// ->select('storeId,uniacid,state,money')
|
|
// ->from('{{%ybwm_table_area}}')
|
|
// ->where('uniacid=:uniacid AND storeId=:storeId AND deleteAt=0 AND display=1', [':uniacid' => $uniacid,':storeId' => $storeId])->orderBy('sort asc,id desc')->all();
|
|
// $week = get_week();
|
|
// $weekArr[] = '周日';
|
|
// $weekArr[] = '周一';
|
|
// $weekArr[] = '周二';
|
|
// $weekArr[] = '周三';
|
|
// $weekArr[] = '周四';
|
|
// $weekArr[] = '周五';
|
|
// $weekArr[] = '周六';
|
|
// for ($i = 0; $i < count($region); $i++) {
|
|
// for ($w = 0; $w < count($week); $w++) {
|
|
// $isToday = 2;
|
|
// if ($week[$w] == date("Y-m-d")) {
|
|
// $isToday = 1;
|
|
// }
|
|
// $num=(new \yii\db\Query())
|
|
// ->from('{{%ybwm_appointment}}')
|
|
// ->where("from_unixtime(serviceAt, '%Y-%m-%d ')='" . $week[$w] . "' AND region=" . $region[$i]['id'] . " AND state!=1 AND deleteAt=0 AND storeId=:storeId", [':storeId' => $storeId])->count()?:0;
|
|
//
|
|
//// $where = "where from_unixtime(serviceAt, '%Y-%m-%d ')='" . $week[$w] . "' AND region=" . $region[$i]['id'] . " AND state!=1 AND deleteAt=0 AND storeId=" . $storeId;
|
|
//// $sql = "SELECT count(id) as count FROM " . tablename('ybcy_appointment') . $where;
|
|
//// $num = pdo_fetch($sql)['count'] ?: 0;
|
|
// $weekNum = date("w", strtotime($week[$w]));
|
|
// $weekNum2 = $weekNum == 0 ? 7 : $weekNum;
|
|
// $region[$i]['weekArr'][] = array(
|
|
// 'week' => $weekArr[$weekNum],
|
|
// 'time' => $week[$w],
|
|
// 'isToday' => $isToday,
|
|
// 'num' => $num,
|
|
// 'isAppointment' => in_array($weekNum2, $weekSet) == true ? 1 : 2,
|
|
// );
|
|
// }
|
|
// }
|
|
// return $this->result(1, '操作成功!',$region);
|
|
}
|
|
public function actionOrderList(){
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->shop_id;
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$page=$result['page']?:1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$timeType=$result['timeType'];
|
|
$keyword=$result['keyword'];
|
|
$region=$result['region'];
|
|
$serviceDay=$result['day'];
|
|
$timeArr=$this->timeArr[$timeType];
|
|
$state=$result['state'];
|
|
$list =(new \yii\db\Query())
|
|
->select(['a.*','from_unixtime(a.createdAt, "%Y-%m-%d %H:%i:%s") as createdAt','u.userName as systemUserName','u.id as uid','u.portrait','r.name as regionName'])
|
|
->from('{{%ybwm_appointment}} as a')
|
|
->leftJoin('{{%ybwm_member}} as u','a.userId=u.id')
|
|
->leftJoin('{{%ybwm_table_area}} as r','a.region=r.id')
|
|
->where('a.uniacid=:uniacid AND a.storeId=:storeId AND a.deleteAt=0 AND a.state>1', [':uniacid' => $uniacid,':storeId' => $storeId]);
|
|
if($state==1){
|
|
$list->andWhere('a.state in (2,3)');
|
|
}
|
|
if($state==2){
|
|
$list->andWhere('a.state in (4,6)');
|
|
}
|
|
if($state==3){
|
|
$list->andWhere('a.state=5');
|
|
}
|
|
if($timeType){
|
|
$list->andWhere('a.serviceAt>=:startTime AND a.serviceAt<=:endTime',[':startTime'=>$timeArr['startTime'],':endTime'=>$timeArr['endTime']]);
|
|
}
|
|
if($keyword){
|
|
$list->andWhere(['or',['like','a.code',$keyword],['like','a.userName',$keyword],['like','a.userTel',$keyword],['like','a.outTradeNo',$keyword]]);
|
|
}
|
|
if ($region) {
|
|
$list->andWhere('a.region='.$region);
|
|
}
|
|
if ($serviceDay) {
|
|
$list->andWhere('a.serviceAt>=:startTime AND a.serviceAt<=:endTime',[':startTime'=>strtotime($serviceDay."00:00:00"),':endTime'=>strtotime($serviceDay."23:59:59")]);
|
|
}
|
|
$res=$list->offset($num)
|
|
->limit($limit)->orderBy('a.id desc')->all();
|
|
$count=$list->count();
|
|
return $this->result(1, '成功',$res,$count);
|
|
}
|
|
//修改预定订单
|
|
public function actionOperationAppointment() {
|
|
$post=axios_request();
|
|
if ($post['type'] == 'adopt') {
|
|
$res = Order::adoptAppointment($post['id']);
|
|
}
|
|
if ($post['type'] == 'confirmArrival') {
|
|
$res = Order::confirmArrival($post['id']);
|
|
}
|
|
if ($post['type'] == 'reject') {
|
|
//拒绝
|
|
$res=Order::reserveCancel($post['id'],2);
|
|
}
|
|
if ($res) {
|
|
return $this->result(1, '操作成功!');
|
|
} else {
|
|
return $this->result(2, '操作失败!');
|
|
}
|
|
}
|
|
} |