public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $page = intval($this->getDataItem('page', 1)); $limit = $this->getConfig()->limit; $offset = ($page - 1) * $limit; $user_id = $this->getUserAuth()->userId; $list = CosOnlineAppointment::query()->columns(['id', 'set_man_id', 'shop_id', 'shop_name', 'online_product_id', 'product_name', 'appointment_time', 'appointment_state', 'set_time', 'type'])->where('appointment_state in(0, 1) and set_man_id = ' . $user_id)->orderBy('appointment_time DESC')->limit($limit, $offset)->execute()->toArray(); $result = []; foreach ($list as $val) { $cover = ''; $price = ''; // 初始单价 if ($val['type'] == 1) { // 美容院 if ($BeautyParlorAttr = BeautyParlorAttr::findFirst('beauty_parlor_id = ' . $val['shop_id'])) { $price = $BeautyParlorAttr->low_price . '元'; } if ($BeautyParlor = BeautyParlor::findFirst('bp_id = ' . $val['shop_id'])) { $cover = $BeautyParlor->bp_cover; } $result[] = ['id' => $val['id'], 'order_id' => $val['shop_id'], 'title' => $val['shop_name'], 'cover' => $cover ? PicUrl::BeautyParlorCover($cover, $this->getDi()) : '', 'price' => $price, 'time' => $val['appointment_time'], 'add_time' => $val['set_time'], 'status' => $val['appointment_state'], 'type' => '1']; } elseif ($val['type'] == '2') { if ($BeautyParlorService = BeautyParlorService::findFirst('service_id = ' . $val['online_product_id'])) { $price = $BeautyParlorService->service_price . '元' . ($BeautyParlorService->service_unit ? '/' . $BeautyParlorService->service_unit : ''); $cover = $BeautyParlorService->service_cover; } $result[] = ['id' => $val['id'], 'order_id' => $val['online_product_id'], 'title' => $val['product_name'] ?: '', 'cover' => $cover ? PicUrl::BeautyParlorCover($cover, $this->getDi()) : '', 'price' => $price, 'time' => $val['appointment_time'], 'add_time' => $val['set_time'], 'status' => $val['appointment_state'], 'type' => '2']; } else { continue; } } $this->setResult($result); }
/** * 更新数据 * @return ResponseResult */ private function updateSave() { $req = $this->request; $response = new ResponseResult(); $response->callback = $req->getPost('callback', null, 'parent.setFormResult'); $response->callbackJavascriptTag = true; $id = intval($req->getPost('bp_id')); if ($id < 1) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!'); return $response; } $name = $req->getPost('bp_name'); $district = intval($req->getPost('bp_district', null, 0)); $address = $req->getPost('bp_address'); $coordinate = $req->getPost('bp_coordinate'); $tel = $req->getPost('bp_tel'); $isSell = intval($req->getPost('bp_is_sell', null, 0)); $medalRefund = intval($req->getPost('bp_medal_refund', null, 0)); $medalVerify = intval($req->getPost('bp_medal_verify', null, 0)); $tags = $req->getPost('bp_tags'); $ownerMobile = $req->getPost('bp_owner_mobile'); $intro = $req->getPost('bp_intro'); ////////////////////////////////////2.0新加参数////2.0新加参数///////2.0新加参数///////2.0新加参数/////////////////////////////// $low_price = $req->getPost("low_price", null, 0); //起步价 $open_year = $req->getPost("open_year", null, 0); //开业年限 $shop_area = $req->getPost("shop_area", null, 0); //店铺面积 $service_num = $req->getPost("service_num", null, 0); //服务项目数量 $op_cl_time = $req->getPost("time", null, ''); //营业时间 $facilities = $req->getPost("facilities", null, ''); //设备设施 if ($op_cl_time != '') { $op_cl_time_arr = explode("至", $op_cl_time); $open_time = trim($op_cl_time_arr[0]); $close_time = trim($op_cl_time_arr[1]); } else { $open_time = ''; $close_time = ''; } if ($low_price < 0 || $open_year < 0 || $shop_area < 0 || $service_num < 0) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '数据不能为空!'); return; } if ($facilities != '') { try { $facilities_json = json_encode($facilities); } catch (\Exception $e) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '数据错误!'); return; } } else { $facilities_json = null; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 判断空数据 if (empty($name) || $district <= 0 || empty($address) || empty($coordinate) || empty($tel) || empty($tags) || empty($intro) || empty($ownerMobile)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!'); return $response; } // 保存封面 $uploadFile = new UploadPic(); $uploadFile->request = $req; $cover = $uploadFile->beautyParlorCover(); if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) { $bpCover = null; } else { $bpCover = $cover[0]; } // 保存基础数据 $coordinate = str_replace(',', ' ', $coordinate); $bp = BeautyParlor::findFirst('bp_id = ' . $id); $data = []; if ($bp->bp_name != $name) { $data['bp_name'] = $name; } if (!!$bpCover) { $data['bp_cover'] = $bpCover; } if ($bp->bp_address != $address) { $data['bp_address'] = $address; } if ($bp->bp_district != $district) { $data['bp_district'] = $district; } $data['bp_coordinate'] = new RawValue("GeomFromText('POINT({$coordinate})')"); if ($bp->bp_tel != $tel) { $data['bp_tel'] = $tel; } if ($bp->bp_owner_mobile != $ownerMobile) { $data['bp_owner_mobile'] = $ownerMobile; } if ($bp->bp_intro != $intro) { $data['bp_intro'] = $intro; } if ($bp->bp_is_sell != $isSell) { $data['bp_is_sell'] = $isSell; } $data['bp_medal'] = strval($medalRefund) . strval($medalVerify); $bp->update($data); /*保存美容院相关数据 */ $bp_attr = BeautyParlorAttr::findFirst("beauty_parlor_id = {$id}"); if (!$bp_attr) { /* $response->sendError(ResponseResultStatus::ERROR, '修改失败!'); return $response; */ $bp_attr = new BeautyParlorAttr(); } $bp_attr->beauty_parlor_id = $id; $bp_attr->close_time = $close_time; $bp_attr->open_time = $open_time; $bp_attr->low_price = $low_price; $bp_attr->open_year = $open_year; $bp_attr->facilities = $facilities_json; $bp_attr->service_num = $service_num; $bp_attr->shop_area = $shop_area; if (!$bp_attr->save()) { $response->sendError(ResponseResultStatus::ERROR, '添加失败!'); } //处理标签 $tagsArr = explode(',', $tags); foreach ($tagsArr as $tag) { $tagDb = BeautyParlorTag::query()->columns('bp_tag_id, bp_id, tag_id')->where('bp_id = :bid: AND tag_id = :tid:')->bind(['bid' => $id, 'tid' => $tag])->execute()->getFirst(); if (!$tagDb) { $tagDb = new BeautyParlorTag(); $tagDb->bp_id = $id; $tagDb->tag_id = $tag; if ($tagDb->save() == false) { $this->databaseErrorLog($tagDb); } } } // 获取所有的标签 $tagList = BeautyParlorTag::query()->where('bp_id = :bid:')->bind(['bid' => $id])->execute(); foreach ($tagList as $t) { if (in_array(strval($t->tag_id), $tagsArr) == false) { $t->delete(); } } // 保存轮播图片 // 轮播图片 $pics = $uploadFile->beautyParlorPics(); if ($pics) { foreach ($pics as $pic) { $picDb = new BeautyParlorPhotos(); $picDb->beauty_parlor_id = $id; $picDb->photo_url = $pic; if ($picDb->save() == false) { $this->databaseErrorLog($picDb); } } } SearchASync::Instance()->noticeSync($id, SearchDataType::BeautyParlors); $response->sendResult('ok'); return $response; }