select("id,name,parent_id")->where(["parent_id" => 0])->asArray()->all(); $req = Yii::$app->request; $pId = $req->get('deviceParentCat'); if (empty($pId)) { $pId = intval($deviceCatParentList[0]['id']); } // 获取子级分类 // $deviceCatChildList = DeviceCat::find()->select("id,name,parent_id")->where(["parent_id" => $pId])->asArray()->all(); $params = array(); $params = $this->dataList(); $params['deviceCatParentList'] = $deviceCatParentList; // $params['deviceCatChildList'] = $deviceCatChildList; $params['catPid'] = 0; $params['catId'] = 0; $params['brandId'] = 0; $params['brandList'] = BrandRepository::getAllAvailableBrands(); $params['search_model_count'] = self::SEARCH_MODEL_COUNT; return $this->render("index", $params); } public function actionInfo() { $req = Yii::$app->request; $id = $req->get('id'); //$userDeviceModel = new UserDeviceModel(); $userDevice = UserDeviceRepository::getUserDeviceInfoById(intval($id)); // 读取历史维修信息 $repalirLogList = RepairOrderRepository::getRepairLogList(intval($id), 1); // 获取二维码 $img_path = QrcodeUtil::previewQrcodeImage($userDevice['number'] . ".png", $userDevice['number']); $userDeviceLogs = UserDeviceLogModel::getUserDeviceLog($id); foreach ($userDeviceLogs as $k => $item) { if ($item['operator_type'] == UserDeviceLogModel::OPERATOR_TYPE_ADMIN) { $operator = SysUserModel::findOne($item['operator_id']); $userDeviceLogs[$k]['operator_name'] = $operator->username; } elseif ($item['operator_type'] == UserDeviceLogModel::OPERATOR_TYPE_ENGINEER) { $operator = EngineerProfileModel::findOne(["engineer_id" => $item['operator_id']]); if (!empty($operator)) { $userDeviceLogs[$k]['operator_name'] = ($operator->firstname . $operator->lastname) ? ($operator->firstname . $operator->lastname) : $operator->nickname; } else { $userDeviceLogs[$k]['operator_name'] = ""; } } elseif ($item['operator_type'] == UserDeviceLogModel::OPERATOR_TYPE_USER) { $user = UserModel::findOne($item['operator_id']); $userDeviceLogs[$k]['operator_name'] = (isset($user) && !empty($user["name"])) ? $user["name"] : ""; } } $params = array(); $params['userDevice'] = $userDevice; $params['repalirLogList'] = $repalirLogList; $params['qrcode_img'] = $img_path; $params['userDeviceLogs'] = $userDeviceLogs; return $this->render("info", $params); } public function actionApply() { $req = Yii::$app->request; $type = empty($req->get('type')) ? 1 : intval($req->get('type')); // 获取父级分类 $deviceCatParentList = DeviceCatRepository::getTopParentCats(); // 获取子级分类 //$deviceCatChildList = DeviceCat::find()->select("id,name,parent_id")->where(["parent_id"=>intval($deviceCatParentList[0]['id'])])->asArray()->all(); $params = array(); $params = $this->getApplyDataList(); $params['deviceCatParentList'] = $deviceCatParentList; //$params['deviceCatChildList'] = $deviceCatChildList; $params['type'] = $type; $params['catPid'] = 0; $params['catId'] = 0; $params['brandId'] = 0; $params['brandList'] = BrandRepository::getAllAvailableBrands(); $params['roles'] = EngineerRole::getRoles('all'); return $this->render("apply", $params); } // 导出审核通过的 public function actionExportApply() { $req = Yii::$app->request; $type = empty($req->get('type')) ? 1 : intval($req->get('type')); //获取父级分类 $deviceCatParentList = DeviceCatRepository::getTopParentCats();// //获取子级分类 //$deviceCatChildList = DeviceCat::find()->select("id,name,parent_id")->where(["parent_id"=>intval($deviceCatParentList[0]['id'])])->asArray()->all(); $params = array(); $params = $this->getApplyDataList(1); $params['deviceCatParentList'] = $deviceCatParentList; //$params['deviceCatChildList'] = $deviceCatChildList; $params['type'] = $type; $params['catPid'] = 0; $params['catId'] = 0; $params['brandId'] = 0; $params['brandList'] = BrandRepository::getAllAvailableBrands(); /** * 后台操作日志 */ AdminLogs::doExport('贴码审核通过的', count($params['userDeviceList'])); return $this->renderPartial("exportApprove", $params); } /** * @return string * 成功 */ public function actionSuccess() { $req = Yii::$app->request; $id = $req->get('id'); $status = $req->get('status'); // 获取申请列表跳转过来的状态 // 读取设备申请信息 $userDeviceModel = new UserDeviceModel(); $userDevice = $userDeviceModel->getBindDeviceApplyUserDeviceById(intval($id)); // 转换成OSS服务器的图片url路径 $bindDeviceApplyImgModel = BindDeviceApplyImgModel::find(); $bindDeviceApplyImgModel->where(['bind_device_apply_id' => $userDevice['bind_device_apply_id']]); $images = $bindDeviceApplyImgModel->all(); $imageArr = array(); if ($images) { foreach ($images as $k => $v) { if (isset($v->path) && $v->path != null && $v->path != '') { $imageArr[] = ImageManager::getUrl($v->path); } } } // 读取申请操作日志 $logResult = BindDeviceApplyLogModel::find()->where(["bind_device_apply_id" => intval($id)])->asArray()->all(); $img_path = QrcodeUtil::previewQrcodeImage($userDevice['qrcode_number'] . ".png", $userDevice['qrcode_number']); // 日志操作人类型:0用户、1工程师、2管理员 $data = array(); foreach ($logResult as $log) { $tmp = array(); $tmp['log_at'] = $log['log_at']; $tmp['content'] = $log['content']; if ($log['operator_type'] == RepairOrderLogModel::OPERATOR_TYPE_USER) { $user = UserModel::findOne(intval($log['operator_id'])); if (!empty($user)) { $tmp['operator_user'] = "客户-" . $user->name; } } else if ($log['operator_type'] == RepairOrderLogModel::OPERATOR_TYPE_ENGINEER) { $user = EngineerProfileModel::findOne(["engineer_id" => intval($log['operator_id'])]); if (!empty($user)) { $tmp['operator_user'] = "工程师-" . $user->firstname . $user->lastname; } } else if ($log['operator_type'] == RepairOrderLogModel::OPERATOR_TYPE_ADMIN) { $user = SysUserProfileModel::findOne(["sys_user_id" => intval($log['operator_id'])]); if (!empty($user)) { $tmp['operator_user'] = "管理员-" . $user->realname; } } else if ($log['operator_type'] == RepairOrderLogModel::OPERATOR_TYPE_SYSTEM) { $tmp['operator_user'] = "系统"; } $tmp['operator_user'] = empty($tmp['operator_user']) ? "" : $tmp['operator_user']; $data[] = $tmp; } return $this->render("success", array( "userDevice" => $userDevice, "operatorList" => $data, 'images' => $imageArr, "qrcode_img" => $img_path, "status" => $status) ); } /** * @return string * 失败 */ public function actionAuth() { $req = Yii::$app->request; $redis = Yii::$app->redis; $id = $req->get('id'); $status = $req->get('status'); // 获取申请列表跳转过来的状态 $userId = Yii::$app->user->id; $redis->lrem(RedisConfig::TODO_BIND_DEVICE_APPLYS, self::REDIS_LIST_DEL_COUNT, $id); //删除redis中对应值的list中的值 $inProcessing = 0; if ($redis->hexists(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $id)) { $str = $redis->hget(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $id); $values = explode("-", $str); if (isset($values[1]) && $userId != $values[1]) { $inProcessing = 1; } } else { $redis->hset(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $id, $id . "-" . $userId); } // 读取设备申请信息 $userDeviceModel = new UserDeviceModel(); $userDevice = $userDeviceModel->getBindDeviceApplyUserDeviceById(intval($id)); if ($userDevice['status'] != BindDeviceApplyModel::STATUS_APPLYING && $userDevice['status'] != BindDeviceApplyModel::STATUS_REVIEW) { return $this->redirect(["success", "id" => $id, "status" => $userDevice['status']]); } // 读取申请失败操作日志 $logResult = BindDeviceApplyLogModel::find()->where(["bind_device_apply_id" => intval($id), "type" => 4])->asArray()->all(); $img_path = QrcodeUtil::previewQrcodeImage($userDevice['qrcode_number'] . ".png", $userDevice['qrcode_number']); $bindDeviceApplyImgModel = BindDeviceApplyImgModel::find(); $bindDeviceApplyImgModel->where(['bind_device_apply_id' => $userDevice['bind_device_apply_id']]); $images = $bindDeviceApplyImgModel->all(); $imageArr = array(); // 当条形码需要执行识别本地图片时,使用这个开关 if ($this->isDownloadImgToLocalServer == 1) { $barcodePath = Yii::getAlias('@webroot') . "/tmp/barcode/"; if (!file_exists($barcodePath)) { mkdir($barcodePath, 0777, true); } if ($images) { foreach ($images as $k => $v) { if (isset($v->path) && $v->path != null && $v->path != '') { $image = ImageManager::getUrl($v->path); $imageArr[] = $image; $imageName = $this->getImageName(ImageManager::getUrl($v->path)); $imagePath = $barcodePath . $imageName; // 判断文件是否已经存在 if (file_exists($imagePath)) { // 判断文件最后修改时间,如果超过一个小时则重新下载图片,防止遇到名字一样的图片却不能覆盖的情况 $filemtime = filemtime($imagePath); if (time() - $filemtime > 3600) { Http::download($image, $imagePath); } } else { Http::download($image, $imagePath); } } } } } else { if ($images) { foreach ($images as $k => $v) { if (isset($v->path) && $v->path != null && $v->path != '') { $image = ImageManager::getUrl($v->path); $imageArr[] = $image; } } } } $params = array(); if ($userDevice['apply_by_type'] == BindDeviceApplyModel::APPLY_TYPE_BY_ENGINEER) { $deviceOrders = BindDeviceApplyModel::bindDeviceApplyHandlingOrder($userDevice['user_device_id'], array('status' => RepairOrderStatus::getHandleStatus())); $params['orders'] = $deviceOrders; } $bindApplyModel = BindDeviceApplyModel::findOne($id); $params['userDevice'] = $userDevice; $params['bindApplyInfo'] = $bindApplyModel ? $bindApplyModel->toArray() : null; $params['images'] = $imageArr; $params['brandList'] = BrandRepository::getAllAvailableBrands(); $params["status"] = $status; $params["img_path"] = $img_path; $params["inProcessing"] = $inProcessing; $params['reasons'] = $this->getAuthFailReasons(); $params['reviewReasons'] = $this->getReviewReasons(); $params['isDownloadImgToLocalServer'] = $this->isDownloadImgToLocalServer; $params['logResult'] = $logResult; return $this->render("auth", $params); } // 审核不通过原因 private function getAuthFailReasons() { /*$arr = array(array('id' => 1, 'content' => '请上传正确的设备序列号图片'), array('id' => 2, 'content' => '请上传正确的设备型号图片'), array('id' => 3, 'content' => '请上传清晰的设备序列号图片'), array('id' => 4, 'content' => '请上传清晰的设备型号图片'), array('id' => 5, 'content' => '该设备不参与本次活动。(办公打印机/复印)'), array('id' => 6, 'content' => '设备正反面图片不属于同一台机器.'), array('id' => 7, 'content' => '二次绑定'), array('id' => 'others', 'content' => '其他'), */ $arr = array( array('id' => 1, 'content' => '无法识别设备序列号'), array('id' => 2, 'content' => '无法识别设备型号'), array('id' => 3, 'content' => '该设备不在业务范围内(传真机/工业机等)'), array('id' => 4, 'content' => '设备正反面图片不属于同一台机器'), array('id' => 5, 'content' => '整机照片不够完整/看不到所帖二维码'), array('id' => 6, 'content' => '图片二维码与系统二维码不相符.'), array('id' => 7, 'content' => '图文印刷店/照相馆/知名房地产公司不采集'), array('id' => 8, 'content' => '生产日期超过15年'), array('id' => 9, 'content' => '贴码位置有误'), array('id' => 10, 'content' => '二次绑定'), array('id' => 'others', 'content' => '其他'), ); return $arr; } // 审核接口 public function actionDoAuth() { $post = Yii::$app->request->post(); $req = Yii::$app->request; $redis = Yii::$app->redis; $auth = intval($post['auth']); $device_apply_id = $post['device_apply_id']; $over_write = $req->post('over_write'); // 从设备申请表读取申请资料,如果不存在,则表明操作无效 $deviceApply = BindDeviceApplyModel::findOne($device_apply_id); if (!$deviceApply) { return $this->renderJson(array("status" => 0, "msg" => "该贴码申请不存在")); exit(); } // 待审核/待复核才允许提交审核操作 if ($deviceApply->status != BindDeviceApplyModel::STATUS_APPLYING && $deviceApply->status != BindDeviceApplyModel::STATUS_REVIEW) { return $this->renderJson(array("status" => 0, "msg" => "该贴码申请不可审核")); exit(); } if ($auth == 1) { if ($over_write == 1) { $result = $this->overWriteReview($deviceApply); } else { $result = $this->approveReview($deviceApply); } } else { $result = $this->rejectReview($deviceApply); } // redis队列中值处理 if ($result['status'] == 1) { //删除redis中对应的值 $redis->lrem(RedisConfig::TODO_BIND_DEVICE_APPLYS, self::REDIS_LIST_DEL_COUNT, $device_apply_id); //删除redis中对应值的list中的值 //删除正在处理的订单 if ($redis->hexists(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $device_apply_id)) { $redis->hdel(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $device_apply_id); } } else { // 先删除redis中对应值,然后再添加一条审核中的 $redis->lrem(RedisConfig::TODO_BIND_DEVICE_APPLYS, self::REDIS_LIST_DEL_COUNT, $device_apply_id); //删除redis中对应值的list中的值 //$redis->lpush(RedisConfig::TODO_BIND_DEVICE_APPLYS,$device_apply_id); } return $this->renderJson($result); } /** * 判断是不是真正的图片 */ private function isImage($filename) { $types = '.gif|.jpeg|.png|.bmp|.jpg'; // 定义检查的图片类型 if (file_exists($filename)) { if ($info = @getimagesize($filename)) return 0; $ext = image_type_to_extension($info['2']); return stripos($types, $ext); } else { return false; } } // 获取图片文件名 public function getImageName($path) { if (!preg_match('/\/([^\/]+\.[a-z]{3,4})$/i', $path, $matches)) die('Use image please'); $image_name = strtolower($matches[1]); return $image_name; } // 覆盖操作 $deviceApply 为新的 apply 记录 private function overWriteReview($deviceApply) { $post = Yii::$app->request->post(); $status = ($post['status'] === '' || empty($post['status'])) ? 0 : $post['status']; // 获取申请列表跳转过来的状态 $device_apply_id = $post['device_apply_id']; $deviceChildCat = $post['cat_id']; $brand_id = $post['brand_id']; $model_id = $post['model']; $factory_time = $post['factory_time']; $serial_no = $post['serial_no']; $userId = Yii::$app->user->id; $owner_id = $deviceApply->owner_id; $address_id = $deviceApply->address_id; $engineer_id = $deviceApply->engineer_id; $qrcode_no = $deviceApply->qrcode_number; // 根据型号获取 型号id $model = ModelModel::find()->where(["brand_id" => $brand_id, "device_cat_id" => intval($deviceChildCat), "id" => $model_id])->asArray()->one(); if (sizeof($model) == 0) { return array("status" => 0, "msg" => "型号不存在,请先补充型号信息"); } $model_id = $model['id']; $user_device_id = null; // 根据二维码编号,获取二维码id $qrcode = QrcodeModel::find()->where(["number" => $qrcode_no])->asArray()->one(); if (sizeof($qrcode) == 0) { return array("status" => 0, "msg" => "无效的二维码编号,请确认"); } // 旧的 user_device 记录 $oldUserDevice = UserDeviceModel::findOne(["serial_no" => $serial_no]); if (empty($oldUserDevice)) { return array("status" => 70, "msg" => "替换失败,找不到对应序列号"); } // 旧二维码ID $oldDeviceQrcodeId = $oldUserDevice->device_qrcode_id; $oldBindDeviceApplyId = $oldUserDevice->bind_device_apply_id; $newUserDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $deviceApply->id]); if (empty($newUserDeviceModel)) { return array("status" => 71, "msg" => "找不到对应用户设备"); } // 是否能覆盖 $canOperate = BindDeviceApplyModel::canOperateDevice($newUserDeviceModel->id); if (!$canOperate) { return array("status" => 72, "msg" => "该设备还有订单在处理,不能覆盖"); } // 获取设备信息 $device = DeviceModel::find()->where(["device_cat_id" => intval($deviceChildCat), "model_id" => $model_id])->asArray()->one(); if (sizeof($device) == 0) { return array("status" => 0, "msg" => "此分类和型号下,无对应设备信息,请确认"); } $transaction = Yii::$app->getDb()->beginTransaction(); try { $device_id = $device['id']; $qrcode_id = $qrcode['id']; //记录数据到userdevice $result = 0; $oldUserDevice->owner_id = $owner_id; $oldUserDevice->engineer_id = $engineer_id; $oldUserDevice->device_id = $device_id; $oldUserDevice->address_id = $address_id; $oldUserDevice->device_qrcode_id = $qrcode_id; $oldUserDevice->bind_device_apply_id = $device_apply_id; $oldUserDevice->factory_time = $factory_time; $oldUserDevice->updated_at = time(); $result = $oldUserDevice->save(); if ($oldBindDeviceApplyId != $device_apply_id) { $tt = time(); BindDeviceApplyModel::updateOldBindDeviceApplyOrders($oldUserDevice->id, $deviceChildCat); BindDeviceApplyModel::updateNewBindDeviceApplyOrders($newUserDeviceModel->id, $deviceChildCat, $oldUserDevice->id); $dbConnection = Yii::$app->db; // 之前旧的申请记录作废 $oldBindDeviceApplyModel = BindDeviceApplyModel::findOne(['id' => $oldBindDeviceApplyId]); if ($oldBindDeviceApplyModel) { $dbConnection->createCommand() ->insert('bind_device_apply_tmp', [ 'id' => $oldBindDeviceApplyModel->id, 'ver' => $oldBindDeviceApplyModel->ver, 'engineer_id' => $oldBindDeviceApplyModel->engineer_id, 'owner_id' => $oldBindDeviceApplyModel->owner_id, 'address_id' => $oldBindDeviceApplyModel->address_id, 'qrcode_number' => $oldBindDeviceApplyModel->qrcode_number, 'status' => $oldBindDeviceApplyModel->status, 'reject_desc' => $oldBindDeviceApplyModel->reject_desc, 'apply_at' => $oldBindDeviceApplyModel->apply_at, 'apply_by_type' => $oldBindDeviceApplyModel->apply_by_type, 'updated_at' => $oldBindDeviceApplyModel->updated_at, 'pass_at' => $oldBindDeviceApplyModel->pass_at, 'cover_at' => $tt, 'old_user_device_id' => $oldUserDevice->id ])->execute(); $oldBindDeviceApplyModel->delete(); } // 新的userDevice 作废 if ($newUserDeviceModel) { //$discardUserDevice = array('updated_at'=>$tt,'device_id'=>0,'device_qrcode_id'=>0,'bind_device_apply_id'=>0); //'bind_device_apply_id'=>$oldBindDeviceApplyId //$newUserDeviceModel->updateAttributes($discardUserDevice); $dbConnection->createCommand() ->insert('user_device_tmp', [ 'id' => $newUserDeviceModel->id, 'device_id' => $newUserDeviceModel->device_id, 'owner_id' => $newUserDeviceModel->owner_id, 'engineer_id' => $newUserDeviceModel->engineer_id, 'address_id' => $newUserDeviceModel->address_id, 'device_qrcode_id' => $newUserDeviceModel->device_qrcode_id, 'bind_device_apply_id' => $newUserDeviceModel->bind_device_apply_id, 'serial_no' => $newUserDeviceModel->serial_no, 'factory_time' => $newUserDeviceModel->factory_time, 'created_at' => $newUserDeviceModel->created_at, 'updated_at' => $newUserDeviceModel->updated_at ])->execute(); $newUserDeviceModel->delete(); } } // 更新之前旧的二维码资料为失效状态 $mQrcode = QrcodeModel::findOne(["id" => $oldDeviceQrcodeId]); $mQrcode->status = QrcodeModel::STATUS_INVALID; $mQrcode->save(); if ($result > 0) { // 更新为绑定成功 $deviceApply->status = BindDeviceApplyModel::STATUS_APPLY_PASS; $deviceApply->pass_at = time(); $deviceApply->save(); // 写入日志 $bindDeviceApplyLog = new BindDeviceApplyLogModel(); $bindDeviceApplyLog->bind_device_apply_id = $device_apply_id; $bindDeviceApplyLog->operator_id = $userId; $bindDeviceApplyLog->operator_type = 2; $bindDeviceApplyLog->type = BindDeviceApplyLogModel::TYPE_CORVER_SUCCESS; $bindDeviceApplyLog->content = "覆盖绑定成功"; $bindDeviceApplyLog->insert(); //更新二维码绑定状态 $modelQrcode = QrcodeModel::findOne(["id" => $qrcode_id]); $modelQrcode->status = QrcodeModel::STATUS_BIND; $modelQrcode->save(); /* 工程师贴码奖励 */ ApplyAwardRule::engineerAddPasteAward($deviceApply); // 普通工程师直接贴码, 触发贴码免佣优惠券处理逻辑 if ($deviceApply->apply_by_type == BindDeviceApplyModel::APPLY_TYPE_BY_DIRECT) { EngineerFreeCommission::onBindDeviceApplySuccess($engineer_id); } // 提交事务 $transaction->commit(); // 记录用户设备日志 $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $device_apply_id]); if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => $oldBindDeviceApplyId, 'content' => "覆盖绑定成功", 'type' => UserDeviceLogModel::TYPE_OVERWRITE_SUCCESS]); } // 获取下一个 $nextid = $this->getNextData($status, $device_apply_id); return array("status" => 1, "msg" => "绑定成功", "nextid" => $nextid); } else { // 记录用户设备日志 $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $device_apply_id]); if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => $oldBindDeviceApplyId, 'content' => "覆盖绑定失败", 'type' => UserDeviceLogModel::TYPE_OVERWRITE_FAIL]); } return array("status" => 0, "msg" => "写入绑定信息失败"); } } catch (Exception $exception) { $transaction->rollBack(); Yii::getLogger()->log($exception->getTraceAsString(), Logger::LEVEL_ERROR); if ($exception instanceof StaleObjectException) { return array("status" => 0, "msg" => "该申请已被其他操作员审核完毕"); } return array("status" => 0, "msg" => "数据库操作失败"); } } // 审核通过 private function approveReview($deviceApply) { $post = Yii::$app->request->post(); $status = ($post['status'] === '' || empty($post['status'])) ? 0 : $post['status']; // 获取申请列表跳转过来的状态 $device_apply_id = $post['device_apply_id']; $deviceChildCat = $post['cat_id']; $brand_id = $post['brand_id']; $model_id = $post['model']; $factory_time = $post['factory_time']; $serial_no = $post['serial_no']; $userId = Yii::$app->user->id; $owner_id = $deviceApply->owner_id; $address_id = $deviceApply->address_id; $engineer_id = $deviceApply->engineer_id; $qrcode_no = $deviceApply->qrcode_number; // 根据型号获取 型号id, 这里不能直接靠 model_id 来判断 要加入传入的 brand_id 和device_cat_id $modelM = ModelModel::find()->where(["brand_id" => $brand_id, "device_cat_id" => intval($deviceChildCat), "id" => $model_id]); $model = $modelM->asArray()->one(); if (sizeof($model) == 0) { return array("status" => 0, "msg" => "型号不存在,请先补充型号信息"); } $model_id = $model['id']; $user_device_id = null; // 根据二维码编号,获取二维码id $qrCodeModel = QrcodeModel::find()->where(["number" => $qrcode_no])->asArray()->one(); if (sizeof($qrCodeModel) == 0) { return array("status" => 0, "msg" => "无效的二维码编号,请确认"); } // 记录的 UserDevice $userDevice = UserDeviceModel::findOne(['bind_device_apply_id' => $device_apply_id]); if (empty($userDevice)) { return array("status" => 100, "msg" => "找不到对应用户设备"); } /* $canOperate = BindDeviceApply::canOperateDevice($userDevice->id); if (!$canOperate) { return array("status" => 101, "msg" => "该设备还有订单在处理,不能提交审核"); }*/ $userDeviceSerialCheck = UserDeviceModel::find()->where(["serial_no" => $serial_no])->asArray()->one(); if (sizeof($userDeviceSerialCheck) > 0) { return array("status" => 99, "msg" => "此设备序列号已经存在,重新版定型号", "data" => $this->getSuccessUserDeviceInfo($userDeviceSerialCheck['id'])); } // 获取设备信息 $device = DeviceModel::find()->where(["device_cat_id" => intval($deviceChildCat), "model_id" => $model_id])->asArray()->one(); if (sizeof($device) == 0) { return array("status" => 0, "msg" => "此分类和型号下,无对应设备信息,请确认"); } $transaction = Yii::$app->getDb()->beginTransaction(); try { $device_id = $device['id']; $qrcode_id = $qrCodeModel['id']; $result = 0; if ($userDevice) { $userDevice->device_id = $device_id; $userDevice->owner_id = $owner_id; $userDevice->engineer_id = $engineer_id; $userDevice->address_id = $address_id; $userDevice->device_qrcode_id = $qrcode_id; $userDevice->serial_no = strtoupper($serial_no); $userDevice->factory_time = $factory_time; $result = $userDevice->save(); $user_device_id = $userDevice->id; } else { // 再次预防 user device 记录 为空 $userDevice = new UserDeviceModel(); $userDevice->device_id = $device_id; $userDevice->owner_id = $owner_id; $userDevice->engineer_id = $engineer_id; $userDevice->address_id = $address_id; $userDevice->device_qrcode_id = $qrcode_id; $userDevice->bind_device_apply_id = $device_apply_id; $userDevice->serial_no = strtoupper($serial_no); $userDevice->factory_time = $factory_time; $result = $userDevice->insert(); $user_device_id = $userDevice->id; } if ($result > 0) { // 更新旧设备订单分类,订单名称暂时不改 BindDeviceApplyModel::updateOldBindDeviceApplyOrders($user_device_id, $deviceChildCat); // 更新为绑定成功 $deviceApply->status = BindDeviceApplyModel::STATUS_APPLY_PASS; $deviceApply->pass_at = time(); $deviceApply->save(); // 写入日志 $bindDeviceApplyLog = new BindDeviceApplyLogModel(); $bindDeviceApplyLog->bind_device_apply_id = $device_apply_id; $bindDeviceApplyLog->operator_id = $userId; $bindDeviceApplyLog->operator_type = 2; $bindDeviceApplyLog->type = BindDeviceApplyLogModel::TYPE_APPLY_PASS; $bindDeviceApplyLog->content = "绑定成功"; $bindDeviceApplyLog->insert(); // 更新二维码绑定状态 $mQrcode = QrcodeModel::findOne(["id" => $qrcode_id]); $mQrcode->status = QrcodeModel::STATUS_BIND; $mQrcode->save(); /* 工程师贴码奖励 */ ApplyAwardRule::engineerAddPasteAward($deviceApply); // 普通工程师直接贴码, 触发贴码免佣优惠券处理逻辑 if ($deviceApply->apply_by_type == BindDeviceApplyModel::APPLY_TYPE_BY_DIRECT) { EngineerFreeCommission::onBindDeviceApplySuccess($engineer_id); } // 提交事务 $transaction->commit(); // 记录用户设备日志 $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $device_apply_id]); if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "审核绑定成功", 'type' => UserDeviceLogModel::TYPE_BIND_SUCCESS]); } // 获取下一个 $nextid = $this->getNextData($status, $device_apply_id); return array("status" => 1, "msg" => "绑定成功", "nextid" => $nextid); } else { // 记录用户设备日志 $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $device_apply_id]); if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "审核绑定失败", 'type' => UserDeviceLogModel::TYPE_BIND_FAIL]); } return array("status" => 0, "msg" => "写入绑定信息失败"); } } catch (Exception $exception) { $transaction->rollBack(); Yii::getLogger()->log($exception->getTraceAsString(), Logger::LEVEL_ERROR); AppLog::DEBUG('= approveReview ='.$exception->getTraceAsString()); if ($exception instanceof StaleObjectException) { return array("status" => 0, "msg" => "该申请已被其他操作员审核完毕"); } return array("status" => 0, "msg" => "数据库操作失败"); } } /** * @param $id * @return array */ private function getSuccessUserDeviceInfo($id) { //$userDeviceModel = new UserDeviceModel(); $userDevice = UserDeviceRepository::getUserDeviceInfoById(intval($id)); // 转换成OSS服务器的图片url路径 $bindDeviceApplyImgModel = BindDeviceApplyImgModel::find(); $bindDeviceApplyImgModel->where(['bind_device_apply_id' => $userDevice['bind_device_apply_id']]); $images = $bindDeviceApplyImgModel->all(); $imageArr = array(); if ($images) { foreach ($images as $k => $v) { if (isset($v->path) && $v->path != null && $v->path != '') { $imageArr[] = ImageManager::getUrl($v->path); } } } $userDevice['apply_at'] = date("Y-m-d H:i:s", $userDevice['apply_at']); // 读取申请操作日志 $logResult = BindDeviceApplyLogModel::find()->where(["bind_device_apply_id" => intval($id)])->asArray()->all(); $img_path = QrcodeUtil::previewQrcodeImage($userDevice['number'] . ".png", $userDevice['number']); return array("userdevice" => $userDevice, "images" => $imageArr, "logresult" => $logResult, "qrcodeimg" => $img_path); } /** * 审核拒绝处理 * @param $deviceApply * @return array * @throws \Exception */ private function rejectReview($deviceApply) { $post = Yii::$app->request->post(); $status = ($post['status'] === '' || empty($post['status'])) ? 0 : $post['status']; // 获取申请列表跳转过来的状态 $transaction = Yii::$app->getDb()->beginTransaction(); try { $device_apply_id = $post['device_apply_id']; $fail_content = $post['fail_content']; // 贴码审核拒绝 $deviceApply->status = BindDeviceApplyModel::STATUS_APPLY_FAIL; $deviceApply->reject_desc = $fail_content; // 保存拒绝原因 $deviceApply->save(); // 写入日志 $bindDeviceApplyLog = new BindDeviceApplyLogModel(); $bindDeviceApplyLog->bind_device_apply_id = $device_apply_id; $bindDeviceApplyLog->operator_id = Yii::$app->user->id; $bindDeviceApplyLog->operator_type = 2; $bindDeviceApplyLog->type = BindDeviceApplyLogModel::TYPE_APPLY_FAIL; $bindDeviceApplyLog->content = '绑定失败: ' . $fail_content; $bindDeviceApplyLog->log_at = time(); $bindDeviceApplyLog->insert(); /** * 发送模板消息: 绑定申请审核不通过 */ if (!YII_ENV_DEV) { // $engineerModel = Engineer::findOne($deviceApply->engineer_id); // if ($engineerModel) { // TemplateMessage::bindDevice($deviceApply, '未知设备', $engineerModel); // } /** * 发送短信通知: 绑定申请审核不通过 */ //SmsMessage::sendBindDeviceFailMsg($engineerModel->phone, '未知设备'); // 绑定设备模板消息足够 } // 提交事务 $transaction->commit(); // 记录用户设备日志 $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $device_apply_id]); if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "贴码审核拒绝", 'type' => UserDeviceLogModel::TYPE_REVIEW_REJECT]); } // 获取下一个 $nextid = $this->getNextData($status, $device_apply_id); return array("status" => 1, "msg" => "操作成功", "nextid" => $nextid); } catch (Exception $exception) { $transaction->rollBack(); Yii::getLogger()->log($exception->getTraceAsString(), Logger::LEVEL_ERROR); if ($exception instanceof StaleObjectException) { return array("status" => 0, "msg" => "该申请已被其他操作员审核完毕"); } return array("status" => 0, "msg" => "数据库操作失败"); } } /** * 获取下一条数据 */ private function getNextData($status, $bindDeviceApplyId) { $redis = Yii::$app->redis; if ($status == BindDeviceApplyModel::STATUS_REVIEW) { //$findnex = BindDeviceApply::find()->where(['status' => $status])->orderBy("id desc")->one(); $redis->lrem(RedisConfig::TOVIEW_BIND_DEVICE_APPLYS, self::REDIS_LIST_DEL_COUNT, $bindDeviceApplyId); $findnex = $redis->rpop(RedisConfig::TOVIEW_BIND_DEVICE_APPLYS); } else if ($status == BindDeviceApplyModel::STATUS_APPLYING) { //$findnex= BindDeviceApply::find()->where(['status' => $status])->orderBy("id desc")->one(); $redis->lrem(RedisConfig::TODO_BIND_DEVICE_APPLYS, self::REDIS_LIST_DEL_COUNT, $bindDeviceApplyId); $findnex = $redis->rpop(RedisConfig::TODO_BIND_DEVICE_APPLYS); } if ($findnex) { return $findnex; } else { return 0; } } /** * 同步待处理审核申请队列 */ public function actionSetDataToRedis() { $redis = Yii::$app->redis; $applyList = BindDeviceApplyModel::find()->where("status in (0,3)")->orderBy("id asc")->all(); $redis->del(RedisConfig::TODO_BIND_DEVICE_APPLYS); $redis->del(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS); $redis->del(RedisConfig::TOVIEW_BIND_DEVICE_APPLYS); foreach ($applyList as $applyItem) { if ($applyItem) { if ($applyItem->status == 0) { $redis->lpush(RedisConfig::TODO_BIND_DEVICE_APPLYS, $applyItem->id); } else if ($applyItem->status == 3) { $redis->lpush(RedisConfig::TOVIEW_BIND_DEVICE_APPLYS, $applyItem->id); } } } $e = new stdClass(); $e->status = true; return $this->renderJson($e); } /** * 判断该申请是否有人在处理 */ public function actionApplyIsProcessing() { $redis = Yii::$app->redis; $post = Yii::$app->request->post(); $e = new stdClass(); $e->status = false; if (empty($post['device_apply_id'])) { $e->msg = '缺少必要参数'; return $this->renderJson($e); } $device_apply_id = $post['device_apply_id']; $applyItem = BindDeviceApplyModel::findOne($device_apply_id); if (empty($applyItem)) { $e->msg = "该申请数据不存在"; return $this->renderJson($e); } $userId = Yii::$app->user->id; if ($redis->hexists(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $device_apply_id)) { $str = $redis->hget(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $device_apply_id); $values = explode("-", $str); if (isset($values[1]) && $userId != $values[1]) { $userInfo = SysUserModel::findOne($values[1]); $e->status = 2; $e->msg = $userInfo->username . "正在处理中"; return $this->renderJson($e); } } $e->status = 1; $e->msg = "跳转正常"; return $this->renderJson($e); } /** * 根据品牌/型号/分类生成设备名称 * 格式: 品牌-型号-类型 * @param $brandId * @param $modelId * @param $deviceCatId * @return string */ static public function generateDeviceName($brandId, $modelId, $deviceCatId) { $deviceName = ''; $brandModel = BrandRepository::selectOne($brandId); if ($brandModel) { $deviceName = $brandModel->chinese_name; } if ($modelId) { $model = ModelModel::findOne($modelId); if ($model) { $deviceName = $deviceName . '-' . $model->model; } } $catModel = DeviceCatRepository::selectOne($deviceCatId); if ($catModel) { $deviceName = $deviceName . '-' . $catModel->name; } return $deviceName; } protected function dataList() { $req = Yii::$app->request; $cat_pid = $req->get('deviceParentCat');//设备一级分类 $cat_id = $req->get('deviceChildCat');//设备二级分类 #$brand = $req->get('brand'); 暂不支持基于品牌查询 $engineer = $req->get('engineer');//绑定工程师 $time_begin = $req->get('time_begin');//绑定时间(起) $time_end = $req->get('time_end');//绑定时间(止) $owner = $req->get('owner');//设备拥有者 $serial_no = $req->get('serial_no');//序列号 $model_no = $req->get('model_no'); //型号 $qrcode_no = $req->get('qrcode_no'); //二维码编号 $get = array(); $get['cat_pid'] = empty($cat_pid) ? 0 : $cat_pid; $get['cat_id'] = empty($cat_id) ? 0 : $cat_id; #可以构建一个解析器。。 $map = array(); // 过滤设备分类 if ($cat_pid > 0) { if ($cat_id > 0) { // 选择了二级分类则精准查找 $map[] = array("=", "d.device_cat_id", $cat_id, "I"); } else { // 仅选择了一级分类, 则查询一级分类下所有子分类的数据 $deviceCatIdArray = array(); $childrens = DeviceCatRepository::getSubCatsByParentId($cat_pid, 'sort_order ASC', false); foreach ($childrens as $child) { $deviceCatIdArray[] = $child->id; } // 父节点 $deviceCatIdArray[] = $cat_pid; $deviceCatIds = '(' . implode(",", $deviceCatIdArray) . ')'; $map[] = array("in", "d.device_cat_id", $deviceCatIds, "I"); // 转换为sql: id IN (1,2,3) } } if (!empty($engineer)) { $map[] = array(" like ", "concat(p.firstname,p.lastname)", "%" . $engineer . "%", "S"); #I : int , S:string $get['engineer'] = $engineer; } if (!empty($serial_no)) { $map[] = array(" like ", "ud.serial_no", "%" . $serial_no . "%", "S"); $get['serial_no'] = $serial_no; } if (!empty($model_no)) { $map[] = array(" like ", "m.model", "%" . $model_no . "%", "S"); $get['model_no'] = $model_no; } if (!empty($qrcode_no)) { $map[] = array(" like ", "dp.qrcode_number", "%" . $qrcode_no . "%", "S"); $get['qrcode_no'] = $qrcode_no; } if (!empty($time_begin)) { $map[] = array(">=", "ud.created_at", strtotime($time_begin), "I"); #I : int , S:string $get['time_begin'] = $time_begin; } if (!empty($time_end)) { $map[] = array("<", "ud.created_at", strtotime($time_end) + SysSettingModel::ONE_DAY_SECONDS, "I"); #I : int , S:string $get['time_end'] = $time_end; } if (!empty($owner)) { $map[] = array("like", "o.name", "%" . $owner . "%", "S"); #I : int , S:string $get['owner'] = $owner; } /** * 分页处理 */ //$userDeviceModel = new UserDeviceModel(); $pageSize = $req->get("pageSize") ? (int)$req->get("pageSize") : 20; $pages = new Pagination(['totalCount' => UserDeviceRepository::getUserDeviceListCount($map), 'pageSize' => $pageSize]); $userDeviceList = UserDeviceRepository::getUserDeviceList($pages->offset, $pages->limit, $map); return [ 'userDeviceList' => $userDeviceList, 'pages' => $pages, 'gets' => $get, ]; } /** * 获取申请列表 */ protected function getApplyDataList($withPage = 0) { $req = Yii::$app->request; $brandId = $req->get("brand"); $cat_pid = $req->get('deviceParentCat');//设备一级分类 $cat_id = $req->get('deviceChildCat');//设备二级分类 #$brand = $req->get('brand'); 暂不支持基于品牌查询 $engineer = $req->get('engineer'); $time_begin = $req->get('time_begin'); $time_end = $req->get('time_end'); $pass_time_begin = $req->get('pass_time_begin'); $pass_time_end = $req->get('pass_time_end'); $owner = $req->get('owner'); $serial_no = $req->get('serial_no');//序列号 $model_no = $req->get('model_no'); //型号 $qrcode_no = $req->get('qrcode_no'); //二维码编号 $status = intval($req->get('status')); $apply_by_type = intval($req->get('apply_by_type')); $role = isset($_GET['role'])?$_GET['role']:-1; $auth_user = $req->get('auth_user');// 审核人员姓名 $get = array(); $get['cat_pid'] = empty($cat_pid) ? 0 : $cat_pid; $get['cat_id'] = empty($cat_id) ? 0 : $cat_id; $get['role'] = $role; #可以构建一个解析器。。 $map = []; if (isset($_GET['status']) && $_GET['status'] !== '') { $map[] = array("=", "dp.status", $status); } else { $status = ''; } $get['status'] = $status; if (isset($_GET['apply_by_type']) && $_GET['apply_by_type'] !== '') { $map[] = array("=", "dp.apply_by_type", $apply_by_type); $apply_by_type = $_GET['apply_by_type']; } else { $apply_by_type = ''; } $get['apply_by_type'] = $apply_by_type; if (!empty($brandId)) { $map[] = array("=", "m.brand_id", intval($brandId)); $get['brandId'] = intval($brandId); } else { $get['brandId'] = 0; } #可以构建一个解析器。。 // 过滤设备分类 if ($cat_pid > 0) { if ($cat_id > 0) { // 选择了二级分类则精准查找 $map[] = array("=", "d.device_cat_id", $cat_id); } else { // 仅选择了一级分类, 则查询一级分类下所有子分类的数据 $deviceCatIdArray = array(); $childrens = DeviceCatRepository::getSubCatsByParentId($cat_pid,'sort_order ASC', false);//find()->where(['parent_id' => $cat_pid])->orderBy('sort_order ASC')->all(); foreach ($childrens as $child) { $deviceCatIdArray[] = $child->id; } //$deviceCatIds = '(' . implode(",", $deviceCatIdArray) . ')'; $map[] = array("in", "d.device_cat_id", $deviceCatIdArray); // 转换为sql: id IN (1,2,3) } } if (!empty($engineer)) { //$map[] = array("=","concat(p.firstname,p.lastname)",$engineer); #I : int , S:string $map[] = array("or", array("like", "concat(p.firstname,p.lastname)", $engineer), array("like", "p.nickname", $engineer)); $get['engineer'] = $engineer; } if (!empty($time_begin)) { $map[] = array(">=", "dp.apply_at", strtotime($time_begin)); #I : int , S:string $get['time_begin'] = $time_begin; } if (!empty($time_end)) { $map[] = array("<", "dp.apply_at", strtotime($time_end) + SysSettingModel::ONE_DAY_SECONDS); #I : int , S:string $get['time_end'] = $time_end; } if (!empty($pass_time_begin)) { $map[] = array(">=", "dp.pass_at", strtotime($pass_time_begin)); #I : int , S:string $get['pass_time_begin'] = $pass_time_begin; } if (!empty($pass_time_end)) { $map[] = array("<", "dp.pass_at", strtotime($pass_time_end) + SysSettingModel::ONE_DAY_SECONDS); #I : int , S:string $get['pass_time_end'] = $pass_time_end; } if (!empty($owner)) { $map[] = array("like", "o.name", $owner); #I : int , S:string $get['owner'] = $owner; } if (!empty($auth_user)) { $get['auth_user'] = $auth_user; } if (!empty($serial_no)) { $map[] = array("like", "ud.serial_no", $serial_no); $get['serial_no'] = $serial_no; } if (!empty($model_no)) { $map[] = array("like", "m.model", $model_no); $get['model_no'] = $model_no; } if (!empty($qrcode_no)) { $map[] = array("like", "dp.qrcode_number", $qrcode_no); $get['qrcode_no'] = $qrcode_no; } if (-1 != $role) { $map[] = array("=", "e.role", $role); } if (count($map) == 1) { $map = $map[0]; } else { array_unshift($map, 'and'); } $bindDeviceApply = new BindDeviceApplyModel(); if ($withPage == 0) { /** * 排序 分页处理 */ $sortHelper = Yii::createObject(Sort::className()); $sortHelper->setAttributes($bindDeviceApply); $sort['apply_at'] = $sortHelper->link('apply_at'); $getSort = $req->get("sort"); $orderBy = !empty($getSort) ? $sortHelper->getOrders() : 'apply_at DESC'; $pageSize = $req->get("pageSize") ? (int)$req->get("pageSize") : 20; $pages = new Pagination(['totalCount' => BindDeviceApplyModel::getApplyBindUserDeviceListCount($map, $status, $auth_user), 'pageSize' => $pageSize]); $userDeviceList = BindDeviceApplyModel::getApplyBindUserDeviceList($pages->offset, $pages->limit, $map, $orderBy, $auth_user); return [ 'userDeviceList' => $userDeviceList, 'pages' => $pages, 'gets' => $get, 'status' => $status, 'apply_by_type' => $apply_by_type, 'sort' => $sort ]; } else { $userDeviceList = $bindDeviceApply->getApplyApproveBindUserDeviceList($map); return [ 'userDeviceList' => $userDeviceList, ]; } } // 更新拥有者 public function actionUpdateOwner() { $req = Yii::$app->request; $id = $req->post('id'); $value = $req->post('value'); $column = $req->post('column'); $e = new stdClass(); $e->success = false; if (empty($value) || empty($id) || empty($column)) { $e->error = 'error update'; return $this->renderJson($e); } // 判断更新序列号 if ($column == "serial_no") { $userDeviceSerialCheck = UserDeviceModel::find()->where(["serial_no" => $value])->asArray()->one(); if (sizeof($userDeviceSerialCheck) > 0) { // 进行设备号二次确认 if ($id == $userDeviceSerialCheck["bind_device_apply_id"]) { $e->error = '提交修改序列号和原来序列号一样!'; return $this->renderJson($e); } else { $e->error = '此设备序列号已经存在,无法重复绑定设备'; return $this->renderJson($e); } } } $bindDeviceApplyModel = BindDeviceApplyModel::find(); $bindDeviceApplyModel->leftJoin("owner", "bind_device_apply.owner_id = owner.id"); $bindDeviceApplyModel->leftJoin("address", "bind_device_apply.address_id = address.id"); $bindDeviceApplyModel->where(['bind_device_apply.id' => $id]); $bindDeviceApplyModel->select(['owner.id as ownerId', "owner.name as ownerName", "owner.type as type", "address.id as addressId", "address.address as address"]); $bindDeviceApplyModel->asArray(); $record = $bindDeviceApplyModel->one(); if (empty($record)) { $e->error = '找不到记录'; return $this->renderJson($e); } else { $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $id]); if ($column == 'company_name') { $ownerModel = OwnerModel::findOne($record['ownerId']); $oldOwner = $ownerModel->name; $ownerModel->name = $value; // 记录用户设备日志 if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "编辑设备拥有者({$oldOwner} => {$value})", 'type' => UserDeviceLogModel::TYPE_EDIT_OWNER]); } if ($ownerModel->save()) { $e->success = true; $e->error = '成功更新'; } else { $e->error = '更新失败'; } } elseif ($column == 'address') { $addressModel = AddressModel::findOne($record['addressId']); $oldAddress = $addressModel->address; $addressModel->address = $value; $addressModel->type = AddressModel::TYPE_DEVICE; // 记录用户设备日志 if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "编辑设备地址({$oldAddress} => {$value})", 'type' => UserDeviceLogModel::TYPE_EDIT_ADDRESS]); } if ($addressModel->save()) { $e->success = true; $e->error = '成功更新'; } else { $e->error = '更新失败'; } } elseif ($column == 'address_detail') { $addressModel = AddressModel::findOne($record['addressId']); $oldAddress = $addressModel->detail; $addressModel->detail = $value; // 记录用户设备日志 if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "编辑详细门牌号({$oldAddress} => {$value})", 'type' => UserDeviceLogModel::TYPE_EDIT_ADDRESS]); } if ($addressModel->save()) { $e->success = true; $e->error = '成功更新'; } else { $e->error = '更新失败'; } } elseif ($column == 'serial_no') { $userdeviceModel = UserDeviceModel::findOne(array("bind_device_apply_id" => $id)); $oldSerialNo = $userdeviceModel->serial_no; $userdeviceModel->serial_no = strtoupper($value); // 记录用户设备日志 if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "编辑设备序列号({$oldSerialNo} => " . strtoupper($value) . ")", 'type' => UserDeviceLogModel::TYPE_EDIT_SERIAL_NO]); } if ($userdeviceModel->save()) { $e->success = true; $e->error = '成功更新'; } else { $e->error = '更新失败'; } } return $this->renderJson($e); } } public function actionDeviceQMap() { return $this->render('deviceQMap'); } /** * 设备地图 * @return string */ public function actionDeviceMap() { if (Yii::$app->request->isPost) { $e = new stdClass(); $e->success = true; $e->item = []; $north_east = $this->request->post('north_east'); $south_west = $this->request->post('south_west'); $north_east = Distance::convertBD09ToGCJ02($north_east[0], $north_east[1]); $south_west = Distance::convertBD09ToGCJ02($south_west[0], $south_west[1]); $bindDeviceApplyModel = BindDeviceApplyModel::find(); $bindDeviceApplyModel->leftJoin("address", "address.id = bind_device_apply.address_id"); $bindDeviceApplyModel->select(["address.latitude", "address.longitude"]); $bindDeviceApplyModel->where(['>', 'bind_device_apply.id', 0]); $bindDeviceApplyModel->andFilterWhere(['<', "address.latitude", $north_east[0]]); $bindDeviceApplyModel->andFilterWhere(['>', "address.latitude", $south_west[0]]); $bindDeviceApplyModel->andFilterWhere(['<', "address.longitude", $north_east[1]]); $bindDeviceApplyModel->andFilterWhere(['>', "address.longitude", $south_west[1]]); $bindDeviceApplyModel->asArray(); //$userDeviceModel->limit(100); $oList = $bindDeviceApplyModel->all(); $rItems = []; foreach ($oList as $k => $v) { $rItems[] = Distance::convertGCJ02ToBD09($v['longitude'], $v['latitude']); } $e->item = $rItems; unset($oList); return $this->renderJson($e); } else { return $this->render('deviceMap'); } } public function getMapDevice($key, $limit = 100) { $redis = Yii::$app->redis; $north_east = $this->request->post('north_east'); $south_west = $this->request->post('south_west'); $ischecked = $this->request->post('ischecked'); $value = $redis->get($key); $e = new stdClass(); $e->success = true; $e->item = ""; $table1 = 'address'; $end = time(); $endT = strtotime(date('Y-m-d')) + 1; $start = $endT - 6 * 24 * 3600; $bindDeviceApplyModel = BindDeviceApplyModel::find(); $bindDeviceApplyModel->leftJoin("address", "address.id = bind_device_apply.address_id"); $bindDeviceApplyModel->select(["address.id as adid", "address.latitude", "address.longitude", "count(*) as mycount"]); $bindDeviceApplyModel->where(['bind_device_apply.status' => BindDeviceApplyModel::STATUS_APPLY_PASS]); //$bindDeviceApplyModel->andFilterWhere(['>','bind_device_apply.apply_at',$start]); //$bindDeviceApplyModel->andFilterWhere(['<','bind_device_apply.apply_at',$end]); $bindDeviceApplyModel->andFilterWhere(['<', "address.latitude", $north_east[0]]); $bindDeviceApplyModel->andFilterWhere(['>', "address.latitude", $south_west[0]]); $bindDeviceApplyModel->andFilterWhere(['<', "address.longitude", $north_east[1]]); $bindDeviceApplyModel->andFilterWhere(['>', "address.longitude", $south_west[1]]); if ($value) { $bindDeviceApplyModel->andWhere("address.id not in (" . rtrim($value, ",") . ")"); } $bindDeviceApplyModel->groupBy('adid'); $bindDeviceApplyModel->asArray(); $bindDeviceApplyModel->offset(0)->limit($limit); $olist = $bindDeviceApplyModel->all(); $item = array('data' => array()); $max = 10; $adids = $value ? $value : ""; if ($olist) { foreach ($olist as $k => $v) { if ($max < $v['mycount']) { $max = $v['mycount']; } $item['data'][] = array('lat' => $v["latitude"], 'lng' => $v["longitude"]); if ($v["adid"]) { $adids .= "{$v["adid"]},"; } } } if ($adids) { if ($value) { $redis->set($key, $adids); } else { $redis->set($key, $adids); } } $item['adids'] = $adids;//$max; //$item['max'] = 5;//$max; $e->item = $item; return $e; } public function actionHeatmap() { if (Yii::$app->request->isPost) { $e = new stdClass(); $e->success = true; $north_east = $this->request->post('north_east'); $south_west = $this->request->post('south_west'); $zoom = $this->request->post('zoom'); /* $distance = 25000; //25公里内的点 $earthRadius = Distance::EARTH_RADIUS; */ $bindDeviceApplyModel = BindDeviceApplyModel::find(); $bindDeviceApplyModel->leftJoin("address", "address.id = bind_device_apply.address_id"); $bindDeviceApplyModel->select(["concat(address.latitude,'_',address.longitude) as latlng", "count(*) as mycount"]); $bindDeviceApplyModel->where(['bind_device_apply.status' => BindDeviceApplyModel::STATUS_APPLY_PASS]); //$bindDeviceApplyModel->andFilterWhere(['>','bind_device_apply.apply_at',$start]); //$bindDeviceApplyModel->andFilterWhere(['<','bind_device_apply.apply_at',$end]); $bindDeviceApplyModel->andFilterWhere(['<', "address.latitude", $north_east[0]]); $bindDeviceApplyModel->andFilterWhere(['>', "address.latitude", $south_west[0]]); $bindDeviceApplyModel->andFilterWhere(['<', "address.longitude", $north_east[1]]); $bindDeviceApplyModel->andFilterWhere(['>', "address.longitude", $south_west[1]]); $bindDeviceApplyModel->groupBy('latlng'); $bindDeviceApplyModel->asArray(); $olist = $bindDeviceApplyModel->all(); $item = array('max' => 10, 'data' => array()); $max = 10; if ($olist) { foreach ($olist as $k => $v) { $latlngTemp = explode('_', $v['latlng']); if ($max < $v['mycount']) { $max = $v['mycount']; } $item['data'][] = array('lat' => $latlngTemp[0], 'lng' => $latlngTemp[1], 'count' => $v['mycount']); } } $item['max'] = 5;//$max; $e->item = $item; return $this->renderJson($e); } else { $req = Yii::$app->request; $deviceCatParentList = DeviceCatRepository::getTopParentCats(); $pId = $req->get('deviceParentCat'); if (empty($pId)) { $pId = intval($deviceCatParentList[0]['id']); } //获取子级分类 $deviceCatChildList = DeviceCatRepository::getSubCatsByParentId($pId); $deviceParentCat = $req->get('deviceParentCat'); $deviceCatId = $req->get('deviceChildCat'); $engineer = $req->get('engineer'); $time_begin = $req->get('time_begin'); $time_end = $req->get('time_end'); $owner = $req->get('owner'); $gets = array(); $gets['cat_pid'] = empty($deviceParentCat) ? 0 : intval($deviceParentCat); if (!empty($deviceCatId)) { $gets['cat_id'] = $deviceCatId; } else { $gets['cat_id'] = 0; } $prams = array('gets' => $gets, 'deviceCatParentList' => $deviceCatParentList, 'deviceCatChildList' => $deviceCatChildList); return $this->render('heatmap', $prams); } } // 搜索关键字 public function actionSearchItem() { $e = new stdClass(); $e->success = false; $e->list = []; $req = Yii::$app->request; $keyword = $req->post('query'); $userDeviceModel = DeviceModel::find(); $userDeviceModel->leftJoin('device_cat', "device_cat.id = device.device_cat_id"); $userDeviceModel->leftJoin('model', "model.id = device.model_id"); $userDeviceModel->leftJoin('device_img', "device_img.device_id = device.id"); $userDeviceModel->select(['device.id as id', 'device.device_name as device_name', 'device.device_cat_id as cat_id', 'device_cat.name as cat_name', 'device_cat.parent_id as cat_parent_id', 'model.id as mode_id', 'model.model as model_no', 'model.brand_id as brand_id', 'device_img.path as img_path']); $userDeviceModel->where(['or', ['like', 'device.device_name', $keyword], ['like', 'device_cat.name', $keyword]]); $userDeviceModel->andWhere(['not like', 'device.device_name', 'JIWORK']); $userDeviceModel->asArray(); $userDeviceModel->limit(15); $deviceList = $userDeviceModel->all(); if ($deviceList) { foreach ($deviceList as $k => $v) { $deviceList[$k]['img_path'] = ImageManager::getUrl($v['img_path'], ImageManager::$STYLE_280); } $e->list = $deviceList; } return $this->renderJson($e); } // 搜设备分类关键字 public function actionSearchCat() { $e = new stdClass(); $e->success = false; $e->list = []; $req = Yii::$app->request; $keyword = $req->post('query'); $userDeviceModel = DeviceModel::find(); $userDeviceModel->leftJoin('device_cat', "device_cat.id = device.device_cat_id"); $userDeviceModel->leftJoin('model', "model.id = device.model_id"); $userDeviceModel->leftJoin('device_img', "device_img.device_id = device.id"); $userDeviceModel->select(['device.id as id', 'device.device_name as device_name', 'device.device_cat_id as cat_id', //'device_cat.name as cat_name','device_cat.parent_id as cat_parent_id', 'model.id as mode_id', 'model.model as model_no', 'model.brand_id as brand_id']); $userDeviceModel->where(['or', ['like', 'device.device_name', $keyword], ['like', 'device_cat.name', $keyword]]); $userDeviceModel->andWhere(['not like', 'device.device_name', 'JIWORK']); $userDeviceModel->asArray(); $userDeviceModel->limit(15); $deviceList = $userDeviceModel->all(); if ($deviceList) { $e->list = $deviceList; } return $this->renderJson($e); } // 保存修改分类 public function actionSaveChange() { $e = new stdClass(); $e->success = false; $req = Yii::$app->request; $device_id = $req->post('device_id'); $bindApplyId = $req->post('id'); if (empty($device_id) || empty($bindApplyId)) { $e->msg = 'ID 或设备为空!'; $this->renderJson($e); } $bindApplyModel = BindDeviceApplyModel::findOne($bindApplyId); if (empty($bindApplyModel)) { $e->msg = '没有该审核记录!'; $this->renderJson($e); } $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $bindApplyId]); if (empty($userDeviceModel)) { $e->msg = '没有该用户设备!'; $this->renderJson($e); } if (0 == $userDeviceModel->device_id) { $e->msg = '该用户设备未绑定过,无法更改类型!'; $this->renderJson($e); } $userDeviceModel->device_id = $device_id; if ($userDeviceModel->save()) { $e->success = true; } else { $e->msg = '更新分类失败!'; } $this->renderJson($e); } // 请求复核原因 private function getReviewReasons() { $reasonArray = [ ['id' => 1, 'content' => '新型号待录入'], ['id' => 2, 'content' => '图片二维码与手动录入二维码不相符'], ['id' => 3, 'content' => '覆盖时序列号相同但机型等其它信息均不同'], ['id' => 4, 'content' => '国外机型'], ['id' => 5, 'content' => '再生机'], ['id' => 'others', 'content' => '其他'] ]; return $reasonArray; } /** * 请求复核 * @return string */ public function actionDoReview() { $req = Yii::$app->request; $redis = Yii::$app->redis; $bindDeviceApplyId = $req->post('id'); $status = ($req->post('status') === '' || empty($req->post('status'))) ? 0 : $req->post('status'); // 获取申请列表跳转过来的状态 $reason = $req->post("reviewReason"); if (empty($bindDeviceApplyId) || empty($reason)) { return $this->renderJson(array("status" => 0, "msg" => "缺少申请ID或理由")); } $bindDeviceApplyModel = BindDeviceApplyModel::findOne($bindDeviceApplyId); if ($bindDeviceApplyModel == false) { return $this->renderJson(array("status" => 0, "msg" => "请求复核失败, 无效贴码申请ID")); } if ($bindDeviceApplyModel->status != BindDeviceApplyModel::STATUS_APPLYING) { return $this->renderJson(array("status" => 0, "msg" => "请求复核失败, 只有待审核状态的申请可以复核")); } $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $bindDeviceApplyId]); if (isset($userDeviceModel->id)) { if (!BindDeviceApplyModel::canOperateDevice($userDeviceModel->id)) { return $this->renderJson(array("status" => 0, "msg" => "该设备还有订单在处理,不能请求复核")); } } $bindDeviceApplyModel->review_reason = $reason; $bindDeviceApplyModel->status = BindDeviceApplyModel::STATUS_REVIEW; $bindDeviceApplyModel->save(); // 记录用户设备日志 $userDeviceModel = UserDeviceModel::findOne(['bind_device_apply_id' => $bindDeviceApplyId]); if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog([ 'user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "请求复核(原因=>{$reason})", 'type' => UserDeviceLogModel::TYPE_REVIEW]); } // 写入日志 $bindDeviceApplyLog = new BindDeviceApplyLogModel(); $bindDeviceApplyLog->bind_device_apply_id = $bindDeviceApplyId; $bindDeviceApplyLog->operator_id = Yii::$app->user->id; $bindDeviceApplyLog->operator_type = 2; $bindDeviceApplyLog->type = BindDeviceApplyLogModel::TYPE_REVIEW; $bindDeviceApplyLog->content = '请求复核'; $bindDeviceApplyLog->log_at = time(); $bindDeviceApplyLog->insert(); // 删除正在处理的订单 if ($redis->hexists(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $bindDeviceApplyId)) { $redis->hdel(RedisConfig::PROCESSING_BIND_DEVICE_APPLYS, $bindDeviceApplyId); } // 获取下一个 $nextid = $this->getNextData($status, $bindDeviceApplyId); return $this->renderJson(array("status" => 1, "msg" => "请求复核成功", "nextid" => $nextid)); } /** * 撤销重审 * @return string */ public function actionDoRevoke() { $req = Yii::$app->request; $bindDeviceApplyId = $req->post('id'); $redis = Yii::$app->redis; $bindDeviceApplyModel = BindDeviceApplyModel::findOne($bindDeviceApplyId); if (false == $bindDeviceApplyModel) { return $this->renderJson(array("status" => 0, "msg" => "撤销重审失败, 无效贴码申请ID")); } $userDeviceModel = UserDeviceModel::findOne(["bind_device_apply_id" => $bindDeviceApplyId]); /* $bindRepairOrderModel = RepairOrder::find(); $user_device_id = isset($userDeviceModel->id)?$userDeviceModel->id:0; $bindRepairOrderModel->where(['repair_device_type'=>RepairOrder::REPAIR_DEVICE_USER_TYPE,'repair_device_id'=>$user_device_id]); $repairOrder = $bindRepairOrderModel->all(); if ($repairOrder){ return $this->renderJson(array("status"=>0, "msg"=>"撤销重审失败, 当前该贴码对应的设备已经有订单")); }*/ if ($bindDeviceApplyModel->status != BindDeviceApplyModel::STATUS_APPLY_PASS && $bindDeviceApplyModel->status != BindDeviceApplyModel::STATUS_APPLY_FAIL) { return $this->renderJson(array("status" => 0, "msg" => "撤销重审失败, 只有审核成功或失败状态的申请可以撤销重审")); } // 审核通过的记录要回退相关处理 if (BindDeviceApplyModel::STATUS_APPLY_PASS == $bindDeviceApplyModel->status) { // 删除用户设备记录 if ($userDeviceModel) { // 更新user_device 里面的 device id 为 0 ,撤销重审核 被拒绝这个id要改为0 $userDeviceModel->device_id = 0; $userDeviceModel->serial_no = ''; $userDeviceModel->save(); } // 二维码状态更新 $qrcodeModel = QrcodeModel::findOne(["number" => $bindDeviceApplyModel->qrcode_number]); if ($qrcodeModel) { $qrcodeModel->status = QrcodeModel::STATUS_UNBIND; $qrcodeModel->save(); } } $bindDeviceApplyModel->status = BindDeviceApplyModel::STATUS_APPLYING; $bindDeviceApplyModel->save(); // 记录用户设备日志 if ($userDeviceModel) { $userDeviceId = $userDeviceModel->id; UserDeviceLogModel::addLog(['user_device_id' => $userDeviceId, 'operator_id' => Yii::$app->user->id, 'operator_type' => UserDeviceLogModel::OPERATOR_TYPE_ADMIN, 'old_user_device_id' => 0, 'content' => "撤销重审", 'type' => UserDeviceLogModel::TYPE_REVIEW_CHECK]); } // 写入日志 $bindDeviceApplyLog = new BindDeviceApplyLogModel(); $bindDeviceApplyLog->bind_device_apply_id = $bindDeviceApplyId; $bindDeviceApplyLog->operator_id = Yii::$app->user->id; $bindDeviceApplyLog->operator_type = 2; $bindDeviceApplyLog->content = '撤销重审'; $bindDeviceApplyLog->type = BindDeviceApplyLogModel::TYPE_RE_AUTH; $bindDeviceApplyLog->log_at = time(); $bindDeviceApplyLog->insert(); $redis->lrem(RedisConfig::TODO_BIND_DEVICE_APPLYS, self::REDIS_LIST_DEL_COUNT, $bindDeviceApplyId); //删除redis中对应值的list中的值 $redis->lpush(RedisConfig::TODO_BIND_DEVICE_APPLYS, $bindDeviceApplyId); return $this->renderJson(array("status" => 1, "msg" => "撤销重审成功")); } // 搜索序列号 public function actionSearchSn() { $e = new stdClass(); $e->success = false; $e->list = []; $req = Yii::$app->request; $keyword = $req->post('query'); $userDeviceModel = UserDeviceModel::find(); $userDeviceModel->select(['id', 'device_id', 'serial_no']); $userDeviceModel->where(['like', 'serial_no', $keyword]); $userDeviceModel->asArray(); $userDeviceModel->limit(10); $deviceList = $userDeviceModel->all(); if ($deviceList) { $e->list = $deviceList; } return $this->renderJson($e); } /** * 更新设备序列号 */ public function actionSerialNoUpdate() { $post = Yii::$app->request->post(); $findone = UserDeviceModel::findOne(["serial_no" => $post['value']]); if ($findone) { if ($findone["id"] == $post['pk']) { return $this->renderJson(array("status" => -1, "msg" => "序列号未做修改,修改失败")); exit; } else { return $this->renderJson(array("status" => -1, "msg" => "该序列号已经存在,修改失败")); exit; } } $order = UserDeviceModel::findOne($post['pk']); $order->serial_no = $post['value']; $result = $order->save(); if ($result) { return $this->renderJson(array("status" => 1, "msg" => "修改成功")); exit; } else { return $this->renderJson(array("status" => -1, "msg" => "修改失败")); exit; } } // 审核图片列表 public function actionApplyImgGallery() { $req = Yii::$app->request; $qRcode = $req->get('qrcode'); $bindDeviceApplyModel = BindDeviceApplyModel::find(); $status = array(BindDeviceApplyModel::STATUS_APPLY_FAIL, BindDeviceApplyModel::STATUS_APPLY_PASS, BindDeviceApplyModel::STATUS_REVIEW); $bindDeviceApplyModel->select(['bind_device_apply.*']); $bindDeviceApplyModel->where(['status' => $status]); if (!empty($qRcode)) { $bindDeviceApplyModel->andWhere(['like', 'qrcode_number', $qRcode]); } $bindDeviceApplyModel->asArray(); $pageSize = $req->get("pageSize") ? (int)$req->get("pageSize") : 48; $pages = new Pagination(['totalCount' => $bindDeviceApplyModel->count(), 'pageSize' => $pageSize]); $userDeviceList = $bindDeviceApplyModel->offset($pages->offset)->limit($pages->limit)->orderBy("apply_at desc")->all(); $bindDeviceApplyIds = []; foreach ($userDeviceList as $k => $v) { $bindDeviceApplyIds[] = $v['id']; } $bindDeviceImgModel = BindDeviceApplyImgModel::find(); $bindDeviceImgModel->where(['bind_device_apply_id' => $bindDeviceApplyIds]); $bindDeviceImgModel->asArray(); $imagesT = $bindDeviceImgModel->all(); $images = array(); foreach ($imagesT as $kk => $vv) { $images[$vv['bind_device_apply_id']][] = $vv; } foreach ($userDeviceList as $k => $v) { $newV = $v; $newV['images'] = isset($images[$v['id']]) ? $images[$v['id']] : []; $userDeviceList[$k] = $newV; } $params = array('applyList' => $userDeviceList, 'pages' => $pages, 'qrcode' => $qRcode, 'flag' => 'apply'); return $this->render("imgGallery", $params); } // 审核图片列表 public function actionCoverImgGallery() { $req = Yii::$app->request; $qRcode = $req->get('qrcode'); $query = new Query(); $query->select('id,qrcode_number')->from('bind_device_apply_tmp'); if (!empty($qRcode)) { $query->where(['like', 'qrcode_number', $qRcode]); } $pageSize = $req->get("pageSize") ? (int)$req->get("pageSize") : 48; $pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => $pageSize]); $userDeviceList = $query->offset($pages->offset)->limit($pages->limit)->orderBy("apply_at desc")->all(); $bindDeviceApplyIds = []; foreach ($userDeviceList as $k => $v) { $bindDeviceApplyIds[] = $v['id']; } $bindDeviceImgModel = BindDeviceApplyImgModel::find(); $bindDeviceImgModel->where(['bind_device_apply_id' => $bindDeviceApplyIds]); $bindDeviceImgModel->asArray(); $imagesT = $bindDeviceImgModel->all(); $images = array(); foreach ($imagesT as $kk => $vv) { $images[$vv['bind_device_apply_id']][] = $vv; } foreach ($userDeviceList as $k => $v) { $newV = $v; $newV['images'] = isset($images[$v['id']]) ? $images[$v['id']] : []; $userDeviceList[$k] = $newV; } $params = array('applyList' => $userDeviceList, 'pages' => $pages, 'qrcode' => $qRcode, 'flag' => 'cover'); return $this->render("imgGallery", $params); } public function actionGetOldImg() { $ids = array(13745, 13751, 13752); $query = new Query(); $query->select('bind_device_apply_img.bind_device_apply_id as bind_device_apply_id, bind_device_apply_img.path as path, bind_device_apply_tmp.old_user_device_id as old_user_device_id') ->from('bind_device_apply_img') ->leftJoin("bind_device_apply_tmp", "bind_device_apply_tmp.id = bind_device_apply_img.bind_device_apply_id") ->where(array('bind_device_apply_img.bind_device_apply_id' => $ids)); $rows = $query->all(); foreach ($rows as $item) { $img_path = ImageManager::getUrl($item['path']); echo '