Exemple #1
0
 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);
 }
Exemple #2
0
 public function run()
 {
     //验证是否登录
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $type = $this->getDataItem('type', 1);
     //预约类型
     $bp_id = intval(trim($this->getDataItem('bp_id', 0)));
     //美容院ID
     $service_id = intval(trim($this->getDataItem('service_id')));
     //服务id
     $set_man = trim($this->getDataItem('set_man'));
     //预约人
     $set_time = trim($this->getDataItem('set_time'));
     //预约时间
     $tel = trim($this->getDataItem('tel'));
     //联系电话
     //验证参数
     if ($bp_id == "" || $set_man == "" || $set_time == "" || $tel == '' || $type == 2 && $service_id == '') {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR);
     }
     if ($this->utf8_strlen($set_man) > 10) {
         return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, "预约人不可超过10个字符");
     }
     //预约时间不可小于当前时间 不可大于7天
     if (strtotime($set_time) < time() || strtotime($set_time) > strtotime(' +7 day')) {
         return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, "预约时间不合法");
     }
     //
     if ($this->utf8_strlen($tel) != 11) {
         return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, "请输入11位电话号码");
     }
     //验证美容院是否可预约
     $bp_name = BeautyParlor::query()->columns(['bp_name'])->where('bp_id = :bp_id: AND bp_state = 1 ')->bind(['bp_id' => $bp_id])->execute()->getFirst();
     if (!$bp_name) {
         return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, "美容院不存在");
     }
     if ($type == 2) {
         //当预约服务时 验证服务是可用
         $service = BeautyParlorService::query()->columns('service_name')->where('service_state>0 and service_is_sell = 1 and beauty_parlor_id=:bid: and service_id = :sid:')->bind(['bid' => $bp_id, 'sid' => $service_id])->execute()->getFirst();
         if (!$service) {
             return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, "服务不可预约");
         }
     }
     $data['online_product_id'] = $service_id;
     $data['product_name'] = empty($service) ? '' : $service->product_name;
     $data['appointment_time'] = $set_time;
     $data['set_man'] = $set_man;
     $data['set_man_id'] = $this->getUserAuth()->userId;
     $data['tel'] = $tel;
     $data['set_time'] = date("Y-m-d h:i:s", time());
     $data["appointment_state"] = 0;
     $data["shop_id"] = $bp_id;
     $data["shop_name"] = $bp_name->bp_name;
     $data['type'] = $type;
     $appointment = new CosOnlineAppointment();
     if ($appointment->save($data)) {
         $this->id = $appointment->id;
         $this->success = 1;
         return $this->setResult(['id' => $this->id, 'success' => $this->success]);
     } else {
         return $this->databaseErrorLog($appointment);
     }
 }
Exemple #3
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $bp_id = intval($this->getDataItem('beauty_parlor_id', 0));
     $appoint_id = intval($this->getDataItem('appoint_id', 0));
     $comment_info = Keyword::Filter($this->getDataItem('content', ''));
     //关键字替换
     $keyword = CosQKeyword::query()->execute()->toArray();
     foreach ($keyword as $k => $v) {
         $comment_info = str_replace($v['keyword'], '***', $comment_info);
     }
     $comment_info = base64_encode(serialize($comment_info));
     //$type = intval($this -> getDataItem('type'));
     $type = $this->getDataItem('type');
     //评论图片
     $up = new UploadPic();
     $comment_photos = json_encode($up->beautyParlorComment());
     if ($type !== null && $type >= 0 && in_array($type, array(0, 1))) {
         if ($type == 0) {
             //添加美容院评论
             if ($bp_id > 0 && !empty($comment_info)) {
                 // 查询最大楼层
                 $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "beauty_parlor_id = :id: and type = 0", "bind" => ["id" => $bp_id]]);
                 $bpc = new BeautyParlorComment();
                 $bpc->user_id = $this->getUserAuth()->userId;
                 $bpc->comment_floor = ($floor ? $floor : 0) + 1;
                 $bpc->beauty_parlor_id = $bp_id;
                 $bpc->comment_info = $comment_info;
                 $bpc->comment_photos = $comment_photos;
                 $bpc->type = $type;
                 if ($bpc->save()) {
                     $this->id = $bpc->comment_id;
                     $this->success = 1;
                 } else {
                     return $this->databaseErrorLog($bpc);
                 }
             } else {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "");
             }
             //评论成功,推送消息
             $branch = BeautyParlor::findFirst("bp_id = {$bp_id}")->toArray();
             $branchId = $branch['branch_id'];
             if (empty($branchId)) {
                 //没有分店,不推送
                 return $this->setResult(['id' => $this->id, 'success' => $this->success]);
             } else {
                 $num = Branch::query()->columns('s.shop_uid')->leftJoin('Apps\\Common\\Models\\CosShop', 'Apps\\Common\\Models\\Branch.shop_id = s.shop_id', 's')->where('Apps\\Common\\Models\\Branch.branch_id = ' . $branchId)->execute()->toArray();
                 $phoneNum = $num[0]['shop_uid'];
                 $param = array('type' => 7, 'ispushservice' => 0, 'phone' => $phoneNum, 'content' => '有人对您的美容院进行了评论,快去看看吧!', 'shop_id' => 0);
                 $push = new Jpush();
                 $rs = $push->setval($param);
                 if (!empty($rs)) {
                     $data = json_decode($rs, true);
                     $status = $data['status'];
                     if ($status == 400) {
                         //数据错误
                         return $this->setResult(['id' => $this->id, 'success' => $this->success]);
                     }
                 } else {
                     $rs = $push->push();
                     return $this->setResult(['id' => $this->id, 'success' => $this->success]);
                 }
             }
         }
         if ($type == 1) {
             //添加预约评论
             if ($bp_id > 0 && $appoint_id > 0 && !empty($comment_info)) {
                 //判断预约是否已被当前用户评论
                 $is_comment = BeautyParlorComment::count(["conditions" => "appointment_id = :id: and beauty_parlor_id = :bp_id: and user_id = :user_id:", "bind" => ["id" => $appoint_id, "bp_id" => $bp_id, "user_id" => $this->getUserAuth()->userId]]);
                 if ($is_comment > 0) {
                     //已评论
                     return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "预约已评论");
                 } else {
                     //查询最大楼层
                     $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "appointment_id = :id: and beauty_parlor_id = :bp_id:", "bind" => ["id" => $appoint_id, "bp_id" => $bp_id]]);
                     $bpc = new BeautyParlorComment();
                     $query = new CosOnlineAppointment();
                     $appoint = $query->findFirst("id = {$appoint_id}");
                     if ($appoint) {
                         $data['state'] = 1;
                         $rs = $appoint->update($data);
                     } else {
                         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "当前预约不存在");
                     }
                     $bpc->user_id = $this->getUserAuth()->userId;
                     $bpc->comment_floor = ($floor ? $floor : 0) + 1;
                     $bpc->beauty_parlor_id = $bp_id;
                     $bpc->comment_info = $comment_info;
                     $bpc->comment_photos = $comment_photos;
                     $bpc->type = $type;
                     $bpc->appointment_id = $appoint_id;
                     if ($bpc->save() && $rs) {
                         $this->id = $bpc->comment_id;
                         $this->success = 1;
                     } else {
                         return $this->databaseErrorLog($bpc);
                     }
                 }
             } else {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "");
             }
             return $this->setResult(['id' => $this->id, 'success' => $this->success]);
         }
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "评论类型错误");
     }
     /*  $bp_id = intval($this->getDataItem('beauty_parlor_id',0));
             $comment_info = Keyword::Filter($this->getDataItem('content',''));
             $up = new UploadPic();
             $comment_photos = json_encode($up->beautyParlorComment());
     
             if($bp_id > 0 && !empty($comment_info)) {
                 // 查询最大楼层
                 $floor = BeautyParlorComment::maximum([
                     "column" => "comment_floor",
                     "conditions" => "beauty_parlor_id = :id:",
                     "bind" => [
                         "id" => $bp_id
                     ]
                 ]);
                 //关键字替换
                 $keyword = CosQKeyword::query() -> execute() -> toArray();
                 foreach ($keyword as $k => $v){
                 	
                 	$comment_info = str_replace($v['keyword'], '***', $comment_info);
                 	//$comment_info = str_replace($v['keyword'], str_repeat('*', strlen($v['keyword'])/3), $comment_info);
                 	
                 }
     
                 $bpc = new BeautyParlorComment();
                 $bpc->user_id = $this->getUserAuth()->userId;
                 $bpc->comment_floor = ($floor ? $floor : 0) + 1;
                 $bpc->beauty_parlor_id=$bp_id;
                 $bpc->comment_info=$comment_info;
                 $bpc->comment_photos=$comment_photos;
                 if($bpc->save()){
                     $this->id = $bpc->comment_id;
                     $this->success = 1;
                 }else{
                     return $this->databaseErrorLog($bpc);
                 }
             } else {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "");
             }
     
             $this->setResult([
                 'id'=>$this->id,
                 'success'=>$this->success
             ]);   */
 }