Esempio n. 1
0
 /**
  * 添加新的美容院
  */
 public function addAction()
 {
     $this->setLeftNav('bp_add');
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar("branch_id", $req->getQuery("branch_id"));
         return;
     }
     $this->view->disable();
     $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');
     $branch_id = $req->getPost("branch");
     //绑定分店ID
     // 输出js
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     // 判断空数据
     if (empty($name) || $district <= 0 || empty($address) || empty($coordinate) || empty($tel) || empty($tags) || empty($intro) || empty($ownerMobile)) {
         $echo('数据不能为空!');
         return;
     }
     try {
         $this->db->begin();
         // 保存封面
         $uploadFile = new UploadPic();
         $uploadFile->request = $req;
         $cover = $uploadFile->beautyParlorCover();
         if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
             if ($_FILES['bp_cover']['error'] == 1) {
                 $echo('封面大小超过了2M!');
                 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
             } else {
                 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件处理异常!');
                 $echo('封面必须上传!');
             }
             return;
         }
         //分店信息
         //$info=Branch::query()->where("branch_id = $branch_id")->execute()->toArray();
         if ($branch_id != '') {
             $info = Branch::findFirst("branch_id = {$branch_id}")->toArray();
         }
         $bpCover = $cover[0];
         // 保存基础数据
         $coordinate = str_replace(',', ' ', $coordinate);
         $bp = new BeautyParlor();
         $bp->bp_name = $name;
         $bp->bp_cover = $bpCover;
         $bp->bp_address = $address;
         $bp->bp_district = $district;
         $bp->bp_coordinate = new RawValue("GeomFromText('POINT({$coordinate})')");
         $bp->bp_tel = $tel;
         $bp->bp_owner_mobile = $ownerMobile;
         $bp->bp_intro = $intro;
         $bp->bp_is_sell = $isSell;
         $bp->bp_medal = strval($medalRefund) . strval($medalVerify);
         $bp->branch_id = $branch_id;
         if ($branch_id != '') {
             $bp->long_time = $info->long_time;
             $bp->start_time = $info->start_time;
             $bp->end_time = $info->end_time;
         }
         $rs_bp = $bp->save();
         if ($rs_bp == false) {
             $echo('保存基础数据异常!');
             $this->databaseErrorLog($bp);
             return;
         }
         /* if($bp->save() == false) {
          	 $echo('保存基础数据异常!');
          	 $this->databaseErrorLog($bp);
          	 return;
          	 } */
         $bpId = $bp->bp_id;
         // 保存标签
         /*$tagsArr = explode(',', $tags);
         	 foreach($tagsArr as $tag) {
         	 $tagDb = new BeautyParlorTag();
         	 $tagDb->bp_id = $bpId;
         	 $tagDb->tag_id = $tag;
         	 if($tagDb->save() == false) {
         	 $this->databaseErrorLog($tagDb);
         	 }
         	 }*/
         $tagsarr = explode(",", $tags);
         foreach ($tagsarr as $k => $tag) {
             $taginfo = BeautyParlorTagInfo::find("tag_id = {$tag} and tag_state = 1")->toArray();
             $count = count($taginfo);
             if ($count < 1) {
                 $echo('没有ID为' . $tag . '的标签!');
             }
             $tagDb = new BeautyParlorTag();
             $tagDb->bp_id = $bpId;
             $tagDb->tag_id = $tag;
             $tagDb->sort = $k + 1;
             $rs_tag = $tagDb->save();
             if ($rs_tag == false) {
                 $this->databaseErrorLog($tagDb);
             }
             /* if($tagDb->save() == false) {
             		 $this->databaseErrorLog($tagDb);
             		 } */
         }
         // 保存轮播图片
         // 轮播图片
         $pics = $uploadFile->beautyParlorPics();
         $error = $_FILES['bp_photos']['error'];
         if (!empty($pics)) {
             foreach ($error as $k => $v) {
                 if ($v == 1) {
                     $echo('轮播图片大小超过了2M!');
                     return;
                 }
             }
             foreach ($pics as $pic) {
                 $picDb = new BeautyParlorPhotos();
                 $picDb->beauty_parlor_id = $bpId;
                 $picDb->photo_url = $pic;
                 $rs_pic = $picDb->save();
                 if ($rs_pic == false) {
                     $this->databaseErrorLog($picDb);
                 }
                 /* if($picDb->save() == false) {
                 		 $this->databaseErrorLog($picDb);
                 		 } */
             }
         } else {
             $echo('封面大小超过了2M!');
             return;
         }
         /* if($pics == false || !is_array($pics) || count($pics) == 0 || $pics[0] == false) {
          	 if($_FILES['bp_photos']['error'] == 1) {
          	 $echo('封面大小超过了2M!');
          	 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
          	 } else {
          	 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件处理异常!');
          	 $echo('封面必须上传!');
          	 }
          	 return;
          	 } */
         /* foreach($pics as $pic) {
          	 $picDb = new BeautyParlorPhotos();
          	 var_dump($pic);
          	 exit;
          	 $picDb->beauty_parlor_id = $bpId;
          	 $picDb->photo_url = $pic;
          	 if($picDb->save() == false) {
          	 $this->databaseErrorLog($picDb);
          	 }
          	 } */
         if ($branch_id != '') {
             //修改分店状态
             $branch = Branch::findFirst("branch_id = {$branch_id}");
             $branch->status = 200;
             $flg = $branch->save();
         }
         SearchASync::Instance()->noticeSync($bpId, SearchDataType::BeautyParlors);
         $this->db->commit();
         $echo($bpId, true);
     } catch (Exception $e) {
         $this->db->rollback();
     }
 }
Esempio n. 2
0
 /**
  * 添加新的美容院
  */
 public function addAction()
 {
     $this->setLeftNav('bp_add');
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar("branch_id", $req->getQuery("branch_id"));
         return;
     }
     // 输出js
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     $this->view->disable();
     $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');
     $branch_id = $req->getPost("branch");
     //绑定分店ID
     ////////////////////////////////////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) {
         $echo('数据不能为空!');
         return;
     }
     if ($facilities != '') {
         try {
             $facilities_json = json_encode($facilities);
         } catch (\Exception $e) {
             $echo('数据错误!');
         }
     } else {
         $facilities_json = null;
     }
     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 判断空数据
     if (empty($name) || $district <= 0 || empty($address) || empty($coordinate) || empty($tel) || empty($tags) || empty($intro) || empty($ownerMobile)) {
         $echo('数据不能为空!');
         return;
     }
     try {
         $this->db->begin();
         // 保存封面
         $uploadFile = new UploadPic();
         $uploadFile->request = $req;
         $cover = $uploadFile->beautyParlorCover();
         if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
             if ($_FILES['bp_cover']['error'] == 1) {
                 $echo('封面大小超过了2M!');
                 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
             } else {
                 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件处理异常!');
                 $echo('封面必须上传!');
             }
             return;
         }
         //分店信息
         //$info=Branch::query()->where("branch_id = $branch_id")->execute()->toArray();
         if ($branch_id != '') {
             $info = Branch::findFirst("branch_id = {$branch_id}")->toArray();
         }
         $bpCover = $cover[0];
         // 保存基础数据
         $coordinate = str_replace(',', ' ', $coordinate);
         $bp = new BeautyParlor();
         $bp->bp_name = $name;
         $bp->bp_cover = $bpCover;
         $bp->bp_address = $address;
         $bp->bp_district = $district;
         $bp->bp_coordinate = new RawValue("GeomFromText('POINT({$coordinate})')");
         $bp->bp_tel = $tel;
         $bp->bp_owner_mobile = $ownerMobile;
         $bp->bp_intro = $intro;
         $bp->bp_is_sell = $isSell;
         $bp->bp_medal = strval($medalRefund) . strval($medalVerify);
         $bp->branch_id = $branch_id;
         $bp->start_time = date('Y-m-d H:i:s', time());
         if ($branch_id != '') {
             $bp->long_time = $info->long_time;
             $bp->start_time = $info->start_time;
             $bp->end_time = $info->end_time;
         }
         $rs_bp = $bp->save();
         if ($rs_bp == false) {
             $echo('保存基础数据异常!');
             $this->databaseErrorLog($bp);
             return;
         }
         /* if($bp->save() == false) {
          	 $echo('保存基础数据异常!');
          	 $this->databaseErrorLog($bp);
          	 return;
          	 } */
         $bpId = $bp->bp_id;
         /*保存美容院相关数据  */
         $bp_attr = new BeautyParlorAttr();
         $bp_attr->beauty_parlor_id = $bpId;
         $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()) {
             $echo('添加失败!');
         }
         // 保存标签
         $tagsArr = explode(',', $tags);
         foreach ($tagsArr as $tag) {
             $tagDb = new BeautyParlorTag();
             $tagDb->bp_id = $bpId;
             $tagDb->tag_id = $tag;
             if ($tagDb->save() == false) {
                 $this->databaseErrorLog($tagDb);
             }
         }
         // 保存轮播图片
         // 轮播图片
         $pics = $uploadFile->beautyParlorPics();
         $error = $_FILES['bp_photos']['error'];
         if (!empty($pics)) {
             foreach ($error as $k => $v) {
                 if ($v == 1) {
                     $echo('轮播图片大小超过了2M!');
                     return;
                 }
             }
             foreach ($pics as $pic) {
                 $picDb = new BeautyParlorPhotos();
                 $picDb->beauty_parlor_id = $bpId;
                 $picDb->photo_url = $pic;
                 $rs_pic = $picDb->save();
                 if ($rs_pic == false) {
                     $this->databaseErrorLog($picDb);
                 }
                 /* if($picDb->save() == false) {
                 		 $this->databaseErrorLog($picDb);
                 		 } */
             }
         } else {
             $echo('封面大小超过了2M!');
             return;
         }
         /* if($pics == false || !is_array($pics) || count($pics) == 0 || $pics[0] == false) {
          	 if($_FILES['bp_photos']['error'] == 1) {
          	 $echo('封面大小超过了2M!');
          	 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
          	 } else {
          	 //$response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件处理异常!');
          	 $echo('封面必须上传!');
          	 }
          	 return;
          	 } */
         /* foreach($pics as $pic) {
          	 $picDb = new BeautyParlorPhotos();
          	 var_dump($pic);
          	 exit;
          	 $picDb->beauty_parlor_id = $bpId;
          	 $picDb->photo_url = $pic;
          	 if($picDb->save() == false) {
          	 $this->databaseErrorLog($picDb);
          	 }
          	 } */
         if ($branch_id != '') {
             //修改分店状态
             $branch = Branch::findFirst("branch_id = {$branch_id}");
             $branch->status = 200;
             $flg = $branch->save();
         }
         SearchASync::Instance()->noticeSync($bpId, SearchDataType::BeautyParlors);
         $this->db->commit();
         $echo($bpId, true);
     } catch (\Exception $e) {
         $this->db->rollback();
     }
 }