$this->store_id]); $status = empty($store->content_page) ? 2 : 1; $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $store->content_page ?? ''; $data['status'] = $status; return $data; } /** * 门店店长申请 */ public function apply() { if (!$this->username) { return $this->apiReturnError('姓名不能为空'); } if (!$this->store_id) { return $this->apiReturnError('所属门店不能为空'); } $model = StoreUser::findOne([ 'user_id' => $this->user_id, 'is_delete' => 0 ]); if ($model) { return $this->apiReturnError('已申请过店长,不能再申请'); } $model = new StoreUser(); $model->user_id = $this->user_id; $model->store_id = $this->store_id; $model->username = $this->username; $model->created_at = time(); $model->user_type = 1; $model->status = 0; if (!$model->save()) { return $this->getModelError($model); } return $this->apiReturnSuccess('提交申请成功'); } /** * 店长预约 */ public function shopowner_make() { if (!$this->store_id) { return $this->apiReturnError('所属门店不能为空'); } if (!$this->date) { return $this->apiReturnError('预约时间不能为空'); } $begintime = date("Y-m-d H:i:s", mktime(0, 0, 0, date('m'), date('d'), date('Y'))); $endtime = date("Y-m-d H:i:s", mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1); $date_time = strtotime($this->date); $begin_time = strtotime($begintime); $end_time = strtotime($endtime); if ($date_time >= $begin_time && $date_time <= $end_time) { return $this->apiReturnError('预约时间不能为当天'); } $model = StoreMake::findOne([ 'make_time' => $this->date, 'user_id' => $this->user_id, 'store_id' => $this->store_id, 'status' => 1 ]); if ($model) { return $this->apiReturnError('已预约过店长,请勿重复预约'); } //预约日期 的 开始跟结束时间 $date_start = strtotime($this->date); $date_end = $date_start + 86400; $all = StoreMake::find()->select('*') ->where(['store_id' => $this->store_id]) ->andWhere(['IN', 'status', [0, 1]]) ->andWhere(['between', 'make_time', $date_start, $date_end - 1]) ->asArray() ->all(); if ($all) { return $this->apiReturnError('店长已安排,请勿重复预约'); } $model = new StoreMake(); $model->user_id = $this->user_id; $model->store_id = $this->store_id; $model->make_time = strtotime($this->date); $model->created_at = time(); $model->msg = $this->data ?? ''; $model->status = 0; if (!$model->save()) { return $this->getModelError($model); } return $this->apiReturnSuccess('预约成功'); } /** * showdoc * @catalog 店长预约 * @title 店长预约-已预约信息 */ public function actionShopownerMakeList() { if (empty($this->store_id)) { return $this->apiReturnError('所属门店不能为空'); } $select = StoreMake::find()->andWhere([ 'store_id' => $this->store_id, 'is_delete' => 0, ])->andWhere([ 'in', 'status', [0, 1] ])->andWhere([ '>=', 'make_time', strtotime('Y-m-d'), ])->select('user_id,make_time')->all(); $res = []; foreach ($select as $key => $val) { $status = 1; if (intval($val['user_id']) === intval($this->user_id)) { $status = 2; } if (!empty($res[$val['make_time']]) && $res[$val['make_time']]['status'] === 2) { continue; # 为自己,直接跳过 } $res[$val['make_time']] = [ 'time' => $val['make_time'], 'status' => $status, 'date' => date('Y-m-d', $val['make_time']), ]; } // 获取本月开始时间 $t = strtotime(date('Y-m-01')); $e = strtotime(date('Y-m-1', strtotime('next month')) . '+1 month -1 day'); $result = []; while (true) { if (!empty($res[$t])) { $result[] = $res[$t]; } else { $result[] = [ 'time' => $t, 'status' => 0, 'date' => date('Y-m-d', $t), ]; } if ($t > $e) { break; } $t += 60 * 60 * 24; } return $this->apiReturnSuccess('success', $result); } /** * 离店 * @return array * @throws \Exception */ public function checkOut() { if (empty($this->store_id)) { return $this->apiReturnError('所属门店不能为空'); } //查询是否有 $all = Order::find()->alias('o') ->leftJoin(['rt' => OrderDetail::tableName()], 'o.id=rt.order_id') ->leftJoin(['s' => Store::tableName()], 'o.store_id=s.id') ->leftJoin(['bj' => StoreBj::tableName()], 'o.store_id=bj.store_id') ->leftJoin(['b' => Box::tableName()], 'b.id=o.coach_id') ->select('s.name as store_name,b.name as box_name,s.store_mobile,bj.mobile as bj_mobile,s.location_detail,s.store_mobile,rt.end_at') ->where(['o.is_pay' => 1, 'o.cancel_status' => 0, 'o.is_delete' => 0, 'o.plugin_sign' => 'box_book']) ->andWhere(['o.status' => 1]) ->andWhere(['o.user_id' => $this->user_id]) ->asArray() ->one(); if (!$all) { return $this->apiReturnError('暂未进行中的订单'); } $redis_name = "cxgyc:store_checkout:" . $this->user_id; $get = FlashStorage::getCache($redis_name); if ($get) { return $this->apiReturnError('已通知保洁人员打扫'); } $sms_sender = new SmsMsgHelper(0); $tpl_type = SmsTpl::getTplKey(3); //查询是否有保洁人员 $bj = StoreBj::find()->where(['store_id' => $this->store_id]) ->andWhere(['status' => 1, 'is_delete' => 0])->asArray()->all(); //没有保洁 通知门店 if (!$bj) { FlashStorage::setCache($redis_name, 1, 60 * 10); $sms_sender->sender($all['store_mobile'], $tpl_type, '86', 0, [ 'store' => $all['store_name'], 'name' => $all['box_name'], 'location' => $all['location_detail'], 'phone' => $all['store_mobile'], ]); return $this->apiReturnSuccess('ok', []); } FlashStorage::setCache($redis_name, 1, 60 * 10); foreach ($bj as $index => $item) { $sms_sender->sender($item['bj_mobile'], $tpl_type, '86', 0, [ 'store' => $all['store_name'], 'name' => $all['box_name'], 'location' => $all['location_detail'], 'phone' => $all['store_mobile'], ]); } return $this->apiReturnSuccess('ok', []); } }